Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix decoding when alphabet contains regex-like special chars #10

Merged
merged 2 commits into from
Nov 29, 2023

Conversation

JordanArmstrong
Copy link
Contributor

The decode method uses String.split to find the chunks it needs to work on. This breaks if the alphabet has RegEx special characters in it.

e.g.

        Sqids sqids = Sqids.builder()
                .alphabet(".\\?")
                .build();
        List<Long> numbers = Arrays.asList(1L, 2L, 3L);
        sqids.decode(sqids.encode(numbers)), numbers);

A simple fix would be to wrap the pattern with Pattern.quote, but I took it as an opportunity to optimize the decode a bit to reduce the number of objects we need to create.

@0x3333 0x3333 self-assigned this Nov 28, 2023
Copy link
Collaborator

@0x3333 0x3333 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me, just a small typo.

src/main/java/org/sqids/Sqids.java Outdated Show resolved Hide resolved
Copy link
Collaborator

@0x3333 0x3333 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me.

@0x3333 0x3333 merged commit 21bc107 into sqids:main Nov 29, 2023
1 check passed
@JordanArmstrong JordanArmstrong deleted the fix/special-chars-in-alphabet branch November 29, 2023 13:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants