juxt / bidi

Bidirectional URI routing
MIT License
993 stars 90 forks source link

RegExp flags not respected by match-pattern #166

Open olivergeorge opened 6 years ago

olivergeorge commented 6 years ago

This issue came up while I tried to setup a case insensitive PatternSegment in my routing table.

Clojurescript re-pattern implementation handle's java style regex flags by picking them off the front of the string and building a compatible js/RegExp object.

(defn re-pattern
  "Returns an instance of RegExp which has compiled the provided string."
  [s]
  (if (instance? js/RegExp s)
    s
    (let [[prefix flags] (re-find #"^\(\?([idmsux]*)\)" s)
          pattern (subs s (count prefix))]
      (js/RegExp. pattern (or flags "")))))

This means a case insensitive route could be written as ["/" {#"(?i)Foo" ::foo}].

Currently this doesn't work because the regex is wrapped in parens before use.

(match-beginning (str "(" (segment-regex-group this) ")") env)

(re-pattern (str regex-pattern "(.*)"))

This means the regex string doesn't start with the regex flags anymore. (?i)Foo becomes ((?i)Foo)(.*) but we need (?i)(Foo)(.*)

Possible fixes:

malcolmsparks commented 6 years ago

Good spot. Yes, a valid issue. Not sure what to do, will sleep on it.