Skip to content

Bug - CompressToEncodedURIComponent does not produce URI-safe output #276

@joaoalpalhao360

Description

@joaoalpalhao360

Issue

We are currently using this library in production to encode small amounts of data into URLs as GET parameters.

The method CompressToEncodedURIComponent is expected to return a URI-safe string. However, this is not the case. The output contains characters that are not safe for direct inclusion in a URI and require additional encoding.

This issue appears to have been previously reported in #72, but the behavior persists.

Reproduction

var test = LZString.compressToEncodedURIComponent("This is a string of very long length that seems to be having a lot of suggestions from the Chrome console as to what I will type next. And so I need to add a LOT more text!!!!!!!!!!!!!!!!!!!!!!!! Added!!!!");

Actual Result

"CoCwlgzgBJUIZQgFwE5gHYHMoHsBmUAbgKYoCeUANjllcVkiFI3EoscQLbRI5QBGxKCDiEM2BNTb5EAV0yZiyMDWh4UOTsxBCAwiA2chAY1U5KQuDz4B3EWwCSUG2EqVmZAA5D0xAB5IAHRQAILoACaIfE6+xJG88OGRCAAyAPLAUJw4KEJI-kgAhMUlpWXlJaFJcaVAA"

The output includes characters such as +, which are not URI-safe and are automatically percent-encoded when used in a URL:

"CoCwlgzgBJUIZQgFwE5gHYHMoHsBmUAbgKYoCeUANjllcVkiFI3EoscQLbRI5QBGxKCDiEM2BNTb5EAV0yZiyMDWh4UOTsxBCAwiA2chAY1U5KQuDz4B3EWwCSUG2EqVmZAA5D0xAB5IAHRQAILoACaIfE6%2BxJG88OGRCAAyAPLAUJw4KEJI-kgAhMUlpWXlJaFJcaVAA"

Expected Result

The method should return a string that is fully URI-safe and does not require any additional encoding before being used as a URI component.

Impact

This behavior breaks the expectation set by the method name and introduces ambiguity about whether additional encoding is required. It can also lead to inconsistent handling of encoded values across different environments.

Request

Please confirm whether this is intended behavior. If not, this should be treated as a bug. If it is intended, the method name or documentation should be updated to reflect that additional URI encoding is required.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions