fix: allow multiple whitespace between coordinate ordinates (OGC WKT) - #48
Open
spokodev wants to merge 1 commit into
Open
fix: allow multiple whitespace between coordinate ordinates (OGC WKT)#48spokodev wants to merge 1 commit into
spokodev wants to merge 1 commit into
Conversation
Under the OGC Simple Features WKT grammar the separator between ordinates in a coordinate tuple is one or more whitespace, so "1 2", "1 2" and "1\t2" denote the same point. The parser accepted a single space and a tab but returned null on two or more spaces. The tuples regex hard-coded a single \s between ordinates, and the ordinate splitters in coords() and multicoords() used split(/\s/g), which yields an empty element (parseFloat NaN) on runs of whitespace. Widen both the regex and the four splits to \s+. This is the ordinate-separator whitespace, distinct from issues mapbox#33 and mapbox#36 which concern whitespace adjacent to the parentheses.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Bug
parse("POINT (1 2)")returnsnullwhileparse("POINT (1 2)")returns{type:'Point',coordinates:[1,2]}. Two or more spaces between the X and Y ordinates of a coordinate tuple break parsing, even though a single space and a tab both parse fine:It affects every geometry type that uses coordinate tuples:
Spec
Under the OGC Simple Features WKT grammar the separator between ordinates inside a coordinate tuple is one or more whitespace, so
1 2,1 2and1\t2all denote the same point. Accepting the single-space and tab forms while rejecting the multi-space form is an internal inconsistency, and real-world WKT (PostGIS output, pretty-printers, hand-aligned columns) commonly pads ordinates with multiple spaces.Root cause
Two spots assume exactly one whitespace between ordinates:
tuplesregex hard-codes a single\s, so on"1 2"it matches only"1"and the second ordinate is left unconsumed, then the closing)check fails andparsereturnsnull.coords()andmulticoords()usesplit(/\s/g), so"1 2".split(/\s/g)yields["1","","2"]andparseFloat("")isNaN. Widening only the regex would inject a spuriousnullordinate, so both need fixing together.Fix
Widen the
tuplesregex separator to\s+and the four ordinate splitters incoords()/multicoords()fromsplit(/\s/g)tosplit(/\s+/g). The bundledwellknown.jsis updated to matchindex.js.Tests
Added assertions that double-spaced
POINT,LINESTRINGandPOLYGONparse to the same GeoJSON as their single-spaced forms. They fail onmaster(returnnull) and pass with this change. The existing suite stays green (lint plus all prior assertions, including the single-space and tab cases and the stringify round-trip).Note
This is the ordinate-separator whitespace (between the X and Y of a tuple). It is distinct from issues #33 and #36, which concern whitespace adjacent to the parentheses (a different code path).