Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RegExp flags not respected by match-pattern #166

Open
olivergeorge opened this issue Dec 11, 2017 · 1 comment
Open

RegExp flags not respected by match-pattern #166

olivergeorge opened this issue Dec 11, 2017 · 1 comment

Comments

@olivergeorge
Copy link

olivergeorge commented Dec 11, 2017

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:

  • global "case insensitive" mode. update match-beginning to use flag and prefix "(?i)" if needed.
  • use helper to change the RegExp PatternSegment so that regex flags are respected. So that (?i)Foo becomes (?i)(Foo). Use this helper when making match-beginning calls.
@malcolmsparks
Copy link
Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants