mathjs icon indicating copy to clipboard operation
mathjs copied to clipboard

fix: #3421 require a space or delimiter after hex, bin, and oct values

Open josdejong opened this issue 8 months ago • 3 comments

Fixes #3421

A simple solution is to not only parse hex characters, but just parse any alpha and digit character after the prefix 0x, 0o, or 0x, and then try to parse the string into a number. When evaluating 0x1k, this will give an error messate "SyntaxError: String "0x1k" is not a valid number".

An alternative solution would be to create separate flows for parsing hex, oct, and bin, with specific functions isHexDigit, isOctDigit and isBinDigit, and then we need a separate check to see if the value is followed by an alpha or digit character and then throw an error like "Unexpected character 'k' (char: 3)". I think though that the former is a more informative error message.

@gwhitney can you have a brief look at this PR?

josdejong avatar Apr 23 '25 09:04 josdejong

Hmm, I had hoped we could get a no-breaking-change version of #3423 into v14 (as discussed in #3421 to hold off on addressing it within #3423), as that would make the parsing system much more modular for fixes like this. Or conversely, if we do merge this into v15 now, and then manage to get #3423 done in v14, this commit in v15 will be extremely in conflict with the commit for #3423 in v14, making the rebase of v15 on develop post #3423 more tricky and in need of noticeable manual merging. Thoughts?

gwhitney avatar Apr 23 '25 13:04 gwhitney

If it's handier we can leave this PR open until after #3423 is merged in v14. After that, we can recreate this PR if needed, it's very small.

josdejong avatar Apr 23 '25 13:04 josdejong

That would make sense to me.

gwhitney avatar Apr 23 '25 16:04 gwhitney

Published now in v15.0.0.

josdejong avatar Oct 10 '25 07:10 josdejong