Description
The 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.