Skip to content

Commit d40b0db

Browse files
committed
Allowed slashes without escaping in regex pattern
1 parent 7d8c84e commit d40b0db

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

js/RegExLexer.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -99,14 +99,15 @@ p.parse = function (str, parseType) {
9999
var groups = [], i = 0, l = str.length;
100100
var o, c, token, prev = null, charset = null, unquantifiable = RegExLexer.UNQUANTIFIABLE;
101101
var charTypes = RegExLexer.CHAR_TYPES;
102-
var closeIndex = str.lastIndexOf("/");
102+
var closeIndex = parseType === 'all' ? str.lastIndexOf("/") : Infinity;
103103

104104
while (i < l) {
105105
c = str[i];
106106

107107
token = {i: i, l: 1, prev: prev};
108108

109-
if (parseType === 'all' && (i == 0 || i >= closeIndex)) {
109+
if (parseType === 'flags' ||
110+
(parseType === 'all' && (i == 0 || i >= closeIndex))) {
110111
this.parseFlag(str, token);
111112
} else if (c == "(" && !charset) {
112113
this.parseGroup(str, token);
@@ -159,7 +160,7 @@ p.parse = function (str, parseType) {
159160
// this may be the start of a range, but we'll need to validate after the next token.
160161
token.type = "range";
161162
} else {
162-
this.parseChar(str, token, charset);
163+
this.parseChar(str, token, charset, parseType !== 'all');
163164
}
164165

165166
if (prev) {
@@ -217,10 +218,10 @@ p.parseFlag = function (str, token) {
217218
token.clear = true;
218219
};
219220

220-
p.parseChar = function (str, token, charset) {
221+
p.parseChar = function (str, token, charset, allowSlash) {
221222
var c = str[token.i];
222223
token.type = (!charset && RegExLexer.CHAR_TYPES[c]) || "char";
223-
if (!charset && c == "/") {
224+
if (!charset && c == "/" && !allowSlash) {
224225
token.err = "fwdslash";
225226
}
226227
if (token.type == "char") {

0 commit comments

Comments
 (0)