question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Short codes with padding are unintentionally considered valid

See original GitHub issue

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:

  1. 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.
  2. Update the implementations to handle the change to short code validation and/or short code recovery (dependent on the decision to allow/disallow)
  3. 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:open
  • Created 4 years ago
  • Comments:15 (14 by maintainers)

github_iconTop GitHub Comments

2reactions
WilliamDennisscommented, Apr 19, 2019

Should shortening of codes with only eight digits be allowed? E.g. 8FVC9G8F+ Should shortening of codes with six digits be allowed? E.g., 8FVC9G00+ Should shortening of codes with two or four digits be allowed? E.g., 8FVC0000+

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.

1reaction
fulldecentcommented, Jun 4, 2021

This issue, and #462, is fixed by https://github.com/google/open-location-code/pull/463

It is specified:

  • Plus Codes with code length less than 8 SHALL NOT be represented as short codes.
  • If both distances are less than 10 degrees, digit places 1–2 MAY be omitted.
  • If both distances are less than 0.5 degrees, digit places 1–2 or 1–4 MAY be omitted.
  • If both distances are less than 1/40 degrees, digit places 1–2, 1–4 or 1–6 MAY be omitted.

This incorporates existing specifications at https://github.com/google/open-location-code/blob/main/docs/specification.md#short-codes.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Quiz: Plagiarism | Academic Integrity - University of Guelph
The following multiple-choice quiz tests your knowledge of what is and what is not considered to be plagiarism, as well as of strategies...
Read more >
<input type="number"> - HTML: HyperText Markup Language
A number input is considered valid when empty and when a single number is entered, but is otherwise invalid. If the required attribute...
Read more >
Civil Commitment and the Mental Health Care Continuum
An apparent shortage of psychiatric beds in many areas has created a situation in which involuntary commitment may be seen as a virtual...
Read more >
ICD-10-CM TABULAR LIST of DISEASES and INJURIES ...
Code chronic current infections to active infectious disease as appropriate. ... C40.10 Malignant neoplasm of short bones of upper limb, unspecified side.
Read more >
TextView - Android Developers
The following code sample shows a typical use, with an XML layout and code to ... android:drawablePadding, The padding between the drawables and...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found