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: Don't parse three consecutive 0's as coordinates [skip ci] #2459
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good. Hopefully less unintentional coordinates parsed now
This does not seem correct. You will fail to parse coordinates that contain 0. |
I strongly recommend that you fix this by test-driven development -- that is, start by writing a set of tests of the regexp, both ones that should work right now (incl e.g. 1000,0,0 or 1002,1002), and negative tests the ones with 000 that you would like to not be parsed as coordinates. The latter will fail with the current code. Then you implement your fix, and verify that all tests now pass. |
Also, I think you can in any case reduce the number of digits to 5. I don't think Wynn uses any coordinates ouside 99999. |
In fact, Static-Storage has a dump of all coordinates that Wynn quests mention (in the first part of the quest). You could even test against those. |
I'm mostly worried about coordinates for quest-specific partial maps. They can be larger than 9999, I think. |
Should be fine now. Essentially,
|
p.shouldNotMatch("195,000,000"); | ||
p.shouldNotMatch("20,000"); | ||
p.shouldNotMatch("2,000"); | ||
p.shouldNotMatch(""); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe also add something like:
p.shouldNotMatch("10591,106,2489");
if we agree that having the whitespace mandatory is a good thing.
This looks generally better, I think. I'm perhaps a bit worried about the requirement of whitespace, but then again, this is only the strict matching. We do have a non-strict version as well, with more flexible parsing abilities, right? |
The whitespace I'm talking about is the Technically it should still match |
It might be time to retire the entire existing expression and create a new one that is more comprehensible and works more properly. Starting by a bunch of examples that should -- and should not -- match the coordinate pattern might be a good way. |
This goes with the assumption that no one will ever type
200,000,000
for the coordinates200,0,0
. Instead of parsing to coordinates, when we see three consecutive zeros, ignore and assume it is a regular number instead.200,00,00 still is parsed to coordinates since that's not a valid way to write 2 million.
This is the only change I made, if it's easier to review this way