Skip to content

Commit

Permalink
mkAttrRegex fixed hard coded string
Browse files Browse the repository at this point in the history
mkAttrRegex has a hard coded string "translate" in regex, I've replaced it with the "attribute", also the function did not make use of custom options attribute.
  • Loading branch information
Erik Kralj committed Apr 5, 2016
1 parent fe80b3d commit 9ba1592
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions lib/extract.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ var _ = require('lodash');
var escapeRegex = /[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g;
var noContext = '$$noContext';

function mkAttrRegex(startDelim, endDelim) {
function mkAttrRegex(startDelim, endDelim, attribute) {
var start = startDelim.replace(escapeRegex, '\\$&');
var end = endDelim.replace(escapeRegex, '\\$&');

Expand All @@ -20,7 +20,11 @@ function mkAttrRegex(startDelim, endDelim) {
start += '(?:\\s*\\:\\:\\s*)?';
}

return new RegExp(start + '\\s*(\'|"|"|')(.*?)\\1\\s*\\|\\s*translate\\s*(' + end + '|\\|)', 'g');
if (!_.isString(attribute) || attribute.length === 0) {
attribute = 'translate';
}

return new RegExp(start + '\\s*(\'|"|"|')(.*?)\\1\\s*\\|\\s*' + attribute + '\\s*(' + end + '|\\|)', 'g');
}

var noDelimRegex = mkAttrRegex('', '');
Expand Down Expand Up @@ -90,7 +94,7 @@ var Extractor = (function () {
this.options.attributes.unshift(this.options.attribute);

this.strings = {};
this.attrRegex = mkAttrRegex(this.options.startDelim, this.options.endDelim);
this.attrRegex = mkAttrRegex(this.options.startDelim, this.options.endDelim, this.options.attribute);
}

Extractor.isValidStrategy = function (strategy) {
Expand Down

0 comments on commit 9ba1592

Please sign in to comment.