Short codes with padding are unintentionally considered valid
See original GitHub issueThe Open Location Code specification mentions that full codes with padding cannot be shortened, which would imply that a short code with padding is invalid. However, the API reference for code validation does not specify anything about allowing or disallowing short codes with padding. And as such, most (if not all) of the implementations will determine short codes with padding as being valid (and short), and even allow them to be recovered. Because of this gap in the specification there are inconsistencies and unexpected results between the different implementations and how short codes with padding are recovered.
Theoretically, recovering a short code with padding can sensibly result in a full code with the same padding. Some implementations (such as JavaScript) do maintain the padding when recovering shortened codes as one might expect. Whereas other implementations (such as Java) do not and always result in a full code with 8 digits (non-padded) where the digits that replace the padding are determined by the recovered coordinates which may be unexpected.
Example:
// Throws exception since specification disallows shortening padded codes
OpenLocationCode.shorten("8FWC2300+", 48.025, 8.075);
// JavaScript returns: "8FWC2300+" (Padded 6 digit code)
// Java returns: "8FWC23GG+" (Non-padded 8 digit code as center of 6 digit code area)
OpenLocationCode.recoverNearest("2300+", 48.025, 8.075);
To resolve this issue, I think the following needs to be done:
- The Open Location Code specification should be updated to define short codes with padding as either being explicitly disallowed (consistent with
shorten()
spec), or explicitly allow it if it makes sense and can reasonably be recovered/shortened. - Update the implementations to handle the change to short code validation and/or short code recovery (dependent on the decision to allow/disallow)
- Update the
test_data/validationTests.csv
to include a padded short code to test that all implementations now conform to the updated spec and handle padded short codes appropriately.
I think the easiest and probably best option is to just explicitly disallow padded short codes to be consistent with disallowing shortening of padded full codes. This would also indirectly resolve these inconsistencies assuming that short code validation is fixed in each implementation.
Issue Analytics
- State:
- Created 4 years ago
- Comments:15 (14 by maintainers)
Top GitHub Comments
In my opinion, the answer is yes to all three, and without restriction (no minimum significant digits requirement).
For the reason that they are still meaningful, even if they may not always be considered particularly useful. E.g.
0000+, San Francisco
can be recovered to a valid plus code, so why restrict it unnecessarily? I think in general that the spec should focus on the algorithm (objectively: can this code be meaningfully resolved) and avoid making usability judgments (subjectively: do we think people should actually use this form). There may be future use-cases we have not thought of, and restricting them unnecessarily doesn’t add much value to me.Case in point: I really like that the spec today doesn’t set short codes to be say “exactly 6 digits” (e.g. RG9C+VH). While this is the common size of shortened code we see (as it maps nicely to greater city areas), other use-cases for even shorter codes, say at a neighborhood level (e.g. 9C+VH), are still viable. This flexibility allows people to innovate on top of plus codes, taking advantage of their useful inherent properties.
I also prefer this approach as it keeps the spec simpler and with less edge cases.
This issue, and #462, is fixed by https://github.com/google/open-location-code/pull/463
It is specified:
This incorporates existing specifications at https://github.com/google/open-location-code/blob/main/docs/specification.md#short-codes.