reject trailing characters in SwitchNode numeric comparison#1178
Merged
facontidavide merged 1 commit intoJul 22, 2026
Merged
Conversation
Collaborator
|
thanks |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
SwitchNode picks a child by comparing its
variableagainst eachcase_Nwith CheckStringEquality, which falls back from a string compare to an integer compare and then a real compare. Thevariableis a blackboard entry, so in practice it often carries a value that came from outside the tree. The integer and real fallbacks call std::from_chars (and std::stoi/std::stod on toolchains without the floating-point from_chars) but never check that the whole string was consumed, so5abc,42xxxx, and even5parse as their leading number and compare equal to case5,42, and5. That routes a selector with trailing bytes to a case it does not actually equal, which is easy to slip past a check that only looked at the string form. I ran into it on a switch whose selector came from a message field. The fix requires full consumption (ptr == end, or pos == size on the stoi/stod path) at all four numeric parses; I also let the real comparison resolve scripting enums the way the integer one already does, so an enum name still matches the double a script stores for it. String equality and legitimate numeric matches like5versus5.0are unchanged.