Skip to content
New issue

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

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

Already on GitHub? # to your account

Unexpected error: "Start and end strings lexicographically inseparable" for 'zero' strings #27

Open
lemuelroberto opened this issue Nov 30, 2024 · 2 comments

Comments

@lemuelroberto
Copy link

Hello,

First of all, thank you for creating and maintaining this library.

I've encountered an unexpected error when attempting to use the base62.mudder() function with the following arguments: base62.mudder('', '0').

This behavior seems unexpected as I would assume that the function should be able to handle empty strings and 'zero' strings like '0', '00', '000'.

Screenshot_2024-11-30_15-29-54

Please let me know if I can provide further details or help with debugging.

Thank you very much.

@fasiha
Copy link
Owner

fasiha commented Dec 19, 2024

Thanks for the note and sorry for the delay—new job uses GitHub also so my mentions have been destroyed! So what's happening here is, because you omit the first argument, we assume you want the left/starting point to be the first symbol in your universe, i.e., 0. Therefore, when you give 0+ as the right/end, the library errors out since there's no space 0 and 0, just as there's no space between 0 and 000.

Does that make sense? You can't find a string that's lexicographically between 0 and 00 in base62.

Note that this works: mudder.base62.mudder('00', ''), i.e., you've flipped the arguments and provided the left/start, and the library will use the last symbol (z) as the right/end since you've omitted it. Would this work for you?

@lemuelroberto
Copy link
Author

@fasiha , please don’t worry about the timing. I truly appreciate your work, and thank you again for your response.

I'm running the latest released version, and I noticed something interesting. When calling base62.mudder('00', ''), the result I got was U - the same as when both a and b are empty strings base62.mudder('', '').

Regarding lexicographical sorting, I found that the JS sort function treats '0' < '00' < '000'. For example: ['000', '00', 'b', '', '0', 'a'].sort() yields: ['', '0', '00', '000', 'a', 'b'] So, based on this, '' < '0' < '00' < '000'.

This behavior doesn’t affect my use case since it’s easy to account for, but I do feel aligning with sort's handling of edge cases might be a better approach. That said, I’m unsure how feasible such a change would be.

What are your thoughts on this? If you think it’s worth pursuing but won’t have time in the coming weeks, I’d be happy to explore a potential solution with your guidance.

Thank you again for creating such a valuable library and for taking the time to engage with the community on this!

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants