Change REGEX_RE to allow use of / in filters #886
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
In mutation or event filtering, it is currently possible to filter using regexp, but not to use the
/
char in a regex.This prevents to filter on namespaced mutation name, which is sad. My personnal example is that I wanted to filter out the mutation (core/logger/log) with the following regexp :
/^((?!core\/logger\/log).)*$/
and it didn't work. Filtering with/^((?!logger).)*$/
did work as expected, but filters too much.I checked the code in
src/devtools/views/vuex/module.js
ansrc/devtools/views/action/module.js
The regexp
REGEX_RE = /^\/(.*?)\/(\w*)/
cuts the regexp at the first/
encountered, making it impossible to use this char in a regexp, no matter how we try to escape it.I see several ways to do solve it:
.*
in REGEXP_RE is not greedy. removing the ? seems to work :REGEX_RE = /^\/(.*)\/(\w*)/
REGEX_RE = /^\/(.*?)\/(\w*)$/
.REGEX_RE = /^\/((?:(?:.*?)(?:\\\/)?)*?)\/(\w*)/
I implemented the last solution, which seems cleaner because closer to the initial design that I may not fully understand, and thus less likely to have side effects. It's also closer to the javascript syntax.
I'm not 100% sure of my regexp choice, but I tested it in what seemed to be representative cases (https://gist.github.com/Etiennef/2ef33b57fc7b63e730db050f8b905ce1)