-
Notifications
You must be signed in to change notification settings - Fork 496
Decode() accepts latitude digits beyond North Pole #184
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
Comments
(Forgot to mention I observed this in the cpp implementation; can't speak to the others.) |
Looking at the Decode() implementation some more, it's clear that it doesn't perform any sort of validation. And maybe that's intentional, in which case the correct "fix" would be for openlocationcode::IsValid() to reject codes such as "F2...". |
Seems to be true for the Java implementation as well. There's isValidCode(String) which does check the first two characters of a plus code - but that method doesn't seem to be called from decode() either directly or indirectly. |
Actually, disregard that. In the Java implementation, an OpenLocationCode object can only be created with a code string that passed the isValidCode() check in the first place. |
@drinckes what do you think about this? Should we modify isValid in the C++ implementation? |
I think maybe this is working as intended, and that what I think of as "IsValid()" is actually fulfilled by "IsFull()" which does appear to validate (albeit inefficiently) the first two digits. |
I'm not a c++ expert so I'm happy to defer to others on what the best solution is. Since we don't throw exceptions, we're going to accept an invalid string and return something. The question is, what should the something be? I'm tending to lean away from adding a flag attribute to the codeArea but I'm reasonably happy with saying that a code area that is all zeros (lat lo, lat hi, lng lo, lng hi, codelen) indicates invalid input, and following @viettaml original suggestion to (at least for C++) add an isValid() to the codearea class. That means:
What do you think? |
SGTM. I'll have a go at implementing this when I have a few minutes. Thanks! |
An alternative (and I know you did just send a pr), would be to refactor decode() to take as arguments the code string, and a pointer to a CodeArea, and return a bool depending on whether the code string was valid:
That would change the method signature though. At first thought that's a disadvantage, but it would mean that because the code would have to be refactored, anyone using this method would be more likely to add this kind of check to it. @viettaml what do you think? (It's ok to say "yeah nah".) |
I'm reluctant to change the syntax of an existing function, though I'm more open to adding or overloading the function. That being said, even after my PR Decode() doesn't do a full job of validating codes, so I wouldn't want users relying on it to do so (they should use "IsFull()" instead or first, which does seem to reject the out-of-range codes that initially prompted this report, in addition to various other syntactic errors). With that in mind, following the philosophy of avoiding duplicated or overlapping functionality in an API, I'm inclined to leave Decode() as-is. By the same argument my PR isn't strictly necessary, and I'd be okay with that too. |
Let's close this since we seem to have settled on doing nothing. ;-) Feel free to reopen if you change your mind! |
A full code MUST match one these regular expressions:
I am working to add this to the specification. And so the above is not valid. |
"C2000000+" is a slice at the North Pole. But Decode() will accept "F2000000+" and return a CodeArea with latitude values of 110 degrees.
Now that I think about it, Decode() has no way of signaling an error other than returning an invalid CodeArea, so maybe the solution is to add an IsValid() method to CodeArea.
The text was updated successfully, but these errors were encountered: