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

handling commas and dots input in parseToken of Parser #7514

Merged
merged 24 commits into from
Jan 13, 2025

Conversation

naronchen
Copy link
Contributor

@naronchen naronchen commented Dec 24, 2024

#7487

Right now I have any input consists only special characters returning a parseError or a quantity with isValid field being false.

this should be all the special characters.
/^[!@#$%^&*()_+-=[]{};':"\|,.<>/?]+$/;

Let me know if thats expected, or we wanna handle just the dots/comas occurrences

@naronchen naronchen requested review from a team, ColinKerr, hl662 and rschili as code owners December 24, 2024 23:03
@naronchen naronchen requested a review from MarcNeely December 24, 2024 23:03
@naronchen naronchen changed the title minor fix on parseToken in Parser handling comas and dots input in parseToken of Parser Dec 26, 2024
@hl662 hl662 changed the title handling comas and dots input in parseToken of Parser handling commas and dots input in parseToken of Parser Jan 3, 2025
Copy link
Contributor

@hl662 hl662 left a comment

Choose a reason for hiding this comment

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

@mathieu-fournier I'll let you chime in on whether we should check only commas and dots, or check all special characters (and if the special characters mentioned are enough or we missing any)

@naronchen
Copy link
Contributor Author

naronchen commented Jan 3, 2025

Just pushed a slightly different fix because Mathieu asked to handle multiple dots and comas mixed into numbers
Now I got these tests cases returning parseError.UnableToConvertParseTokensToQuantity

      "10..",
      "1.2,,3..4...7",
      ",,3..",
      "12..34",
      "1.2.3",
      "..10",
      "1...2",
      "1..",
      "1..,",
      "10,20,30..40",
      "1..e2",
      "1e..2",
      "1e2..",
      "1...2e3",
      "1e2..,3",

the ones with comas is a bit tricky

     "1,,2", // returns 12
     "1.,2", // returns 1.2

the parsing skips comas because the parsing method thinks its a thousands separator so it ignores it, will look into it more.

@rschili
Copy link
Contributor

rschili commented Jan 7, 2025

the ones with comas is a bit tricky

     "1,,2", // returns 12
     "1.,2", // returns 1.2

the parsing skips comas because the parsing method thinks its a thousands separator so it ignores it, will look into it more.

Oh, but if the algorithm detects this as thousands separator, it should not just strip it but instead consider its meaning.
I cannot find any notion that can be considered a standard, were for example "1,," would be used to represent "1,000,000"
"1,,2" probably does not represent a valid number in any standard. Neither does "1,"
I'd vote to fail here...

@naronchen
Copy link
Contributor Author

naronchen commented Jan 9, 2025

just pushed a fix handling multiple comas case. it passes all the tests but I just dont feel very secure with regular expression solutions. Couldnt think of a better fix at the moment. Let me know what you think.

(cpp side behaves similarly with ignoring comas, I can work on that afterwards)


This one probably wont work with Indian numbering system? i know they group numbers in 1,00,00,000. I wonder if coma is added as a thousandSeparator if we were to use that system.


Just talked with Rob, gonna revert this commit and do loose checking instead


talked with Colin (apparently he is closest of being UX responsible for core-quantity :) ). Made the call to ignore the comas now and i just logged this proposal in backlog

@naronchen naronchen enabled auto-merge (squash) January 13, 2025 19:52
@naronchen naronchen merged commit 4d7dbf6 into master Jan 13, 2025
16 checks passed
@naronchen naronchen deleted the naron/issue7424 branch January 13, 2025 21:27
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.

3 participants