Details
-
Type:
Defect
-
Status:
Closed
-
Priority:
Minor
-
Resolution: Declined
-
Affects Version/s: None
-
Fix Version/s: None
-
Component/s: None
-
Labels:None
Description
I ran into a strange case where CLJS emitted invalid code based on a poorly formatted regex that escaped / incorrectly.
Looking at such a regex, along with two similar but well formed regexes, passing through tools.reader:
(str #"/") => "\/" (str #"\/") => "\\/" (str #"\\/") => "\\\\/"
But what does
"\\/"
Looking at Clojure execution of these regexes:
(re-find #"/" "\/") => "/" (re-find #"\/" "\/") => "/" (re-find #"\\/" "\/") => "\\/"
ie.
#"\/"
#"/"
Things get more unfortunate once CLJS get's involved, it does not expect the "heisen" regex - and the "dangling escape" ends up capturing the forward slash's escape, ie. an prematurely terminating regex is emitted.
Despite Clojure's existing "fortuitous" behaviour, perhaps the correct behaviour is to throw a reader exception for such regexes, as it does for
"\/"
Alternatively, if
#"\/"
"/"
"\\/"
Happy to provide the patch, whichever way you lean for the solution.
Note that JIRA has done some strange formatting on some strings here, not sure how to solve this (perhaps best to read the markup directly)