8000 RegExp flags not respected by match-pattern · Issue #166 · juxt/bidi · GitHub
[go: up one dir, main page]

Skip to content

RegExp flags not respected by match-pattern #166

Open

Description

@olivergeorge

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.

Activity

  1. malcolmsparks commented on Dec 11, 2017

    @malcolmsparks

    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      0