[CLJ-1252] Clojure reader (incorrectly) accepts keywords starting with a number Created: 04/Sep/13 Updated: 31/Oct/13 Resolved: 31/Oct/13
|Affects Version/s:||Release 1.5|
|Fix Version/s:||Release 1.6|
|Patch:||Code and Test|
The reader page at http://clojure.org/reader states that symbols (and keywords) cannot start with a number and the regex used in LispReader (and EdnReader) also has this intention. But:
Cause: The pattern for keywords is: "[:]?([\D&&[^/]].*/)?(/|[\D&&[^/]][^/]*)". The intention of the [\D&&[^/]] is to accept all non-digits except /. However, if the : matches and 5 does not, the regex will backtrack and unmatch the :, instead matching it in the non-digit charset. The whole match is sent on in the code and the : is stripped later.
Solution: Prevent back-tracking for the first : match by using the possessive quantifier ?+ instead of ?. Once the first : is matched, it will not backtrack to it. (This is also faster.) The patch makes this change in LispReader and EdnReader, updates a couple tests that were using number keywords, and adds a new negative test to check that :5 isn't read.
Screened by: Alex Miller
|Comment by Andy Fingerhut [ 05/Sep/13 5:25 PM ]|
Given how far this one is along now, perhaps
|Comment by Alex Miller [ 31/Oct/13 9:39 PM ]|
Because this broke existing code (several lib projects like java.jdbc), we have rolled this back. Will follow up with an alternate ticket to address this in some other way.