diff --git a/CHANGELOG.md b/CHANGELOG.md index 4a14870..6049c57 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +### 4.3.4 + +* Do not add `g` flag to regex if it already exists + ### 4.3.3 * Switch to `named-js-regexp` instead of `xregexp` for `parse` method diff --git a/lib/helpers.js b/lib/helpers.js index b5f7342..53eb715 100644 --- a/lib/helpers.js +++ b/lib/helpers.js @@ -388,7 +388,9 @@ function parse(data, regex) { } const options = assign({ flags: '' }, opts); - options.flags += 'g'; + if (options.flags.indexOf('g') === -1) { + options.flags += 'g'; + } const messages = []; const compiledRegexp = NamedRegexp(regex, options.flags); diff --git a/spec/helper-spec.coffee b/spec/helper-spec.coffee index 4450580..3623ea1 100644 --- a/spec/helper-spec.coffee +++ b/spec/helper-spec.coffee @@ -152,6 +152,17 @@ describe 'linter helpers', -> results = helpers.parse(input, regex, {flags: "i"}) expect(results).toEqual(output) + regex = 'type:(?.+) message:(?.+)' + input = 'TYPE:type message:message' + output = [( + type: 'type' + text: 'message' + filePath: null + range: [[0, 0], [0, 0]] + )] + results = helpers.parse(input, regex, {flags: "gi"}) + expect(results).toEqual(output) + describe '::find', -> it 'cries when no argument is passed', -> expect -> diff --git a/src/helpers.js b/src/helpers.js index be6e2ae..21ad5a0 100644 --- a/src/helpers.js +++ b/src/helpers.js @@ -332,7 +332,9 @@ export function parse(data, regex, opts = {}) { } const options = assign({flags: ''}, opts) - options.flags += 'g' + if (options.flags.indexOf('g') === -1) { + options.flags += 'g' + } const messages = [] const compiledRegexp = NamedRegexp(regex, options.flags)