@cucumber/tag-expressions
Advanced tools
Comparing version 4.0.2 to 4.1.0
@@ -87,3 +87,3 @@ "use strict"; | ||
const c = expr.charAt(i); | ||
if ('\\' === c) { | ||
if ('\\' === c && !isEscaped) { | ||
isEscaped = true; | ||
@@ -168,3 +168,3 @@ } | ||
toString() { | ||
return this.value.replace(/\(/g, '\\(').replace(/\)/g, '\\)'); | ||
return this.value.replace(/\\/g, '\\\\').replace(/\(/g, '\\(').replace(/\)/g, '\\)'); | ||
} | ||
@@ -171,0 +171,0 @@ } |
@@ -24,2 +24,9 @@ "use strict"; | ||
], | ||
['a\\\\ and b', '( a\\\\ and b )'], | ||
['\\a and b', '( a and b )'], | ||
['a\\ and b', '( a and b )'], | ||
['a and b\\', '( a and b )'], | ||
['( a and b\\\\)', '( a and b\\\\ )'], | ||
['a\\\\\\( and b\\\\\\)', '( a\\\\\\( and b\\\\\\) )'], | ||
['(a and \\b)', '( a and b )'], | ||
// a or not b | ||
@@ -91,4 +98,24 @@ ]; | ||
}); | ||
it('evaluates expressions with escaped backslash', function () { | ||
const expr = (0, src_1.default)('x\\\\ or(y\\\\\\)) or(z\\\\)'); | ||
assert_1.default.strictEqual(expr.evaluate([]), false); | ||
assert_1.default.strictEqual(expr.evaluate(['x\\']), true); | ||
assert_1.default.strictEqual(expr.evaluate(['y\\)']), true); | ||
assert_1.default.strictEqual(expr.evaluate(['z\\']), true); | ||
assert_1.default.strictEqual(expr.evaluate(['x']), false); | ||
assert_1.default.strictEqual(expr.evaluate(['y)']), false); | ||
assert_1.default.strictEqual(expr.evaluate(['z']), false); | ||
}); | ||
it('evaluates expressions with backslash', function () { | ||
const expr = (0, src_1.default)('\\x or y\\ or z\\'); | ||
assert_1.default.strictEqual(expr.evaluate([]), false); | ||
assert_1.default.strictEqual(expr.evaluate(['x']), true); | ||
assert_1.default.strictEqual(expr.evaluate(['y']), true); | ||
assert_1.default.strictEqual(expr.evaluate(['z']), true); | ||
assert_1.default.strictEqual(expr.evaluate(['\\x']), false); | ||
assert_1.default.strictEqual(expr.evaluate(['y\\']), false); | ||
assert_1.default.strictEqual(expr.evaluate(['z\\']), false); | ||
}); | ||
}); | ||
}); | ||
//# sourceMappingURL=tag_expression_parser_test.js.map |
{ | ||
"name": "@cucumber/tag-expressions", | ||
"version": "4.0.2", | ||
"version": "4.1.0", | ||
"description": "Cucumber Tag Expression parser", | ||
@@ -26,4 +26,4 @@ "main": "dist/src/index.js", | ||
"@types/mocha": "9.0.0", | ||
"@types/node": "14.17.15", | ||
"mocha": "9.1.1", | ||
"@types/node": "14.17.21", | ||
"mocha": "9.1.2", | ||
"ts-node": "10.2.1", | ||
@@ -30,0 +30,0 @@ "typescript": "4.4.3" |
@@ -87,3 +87,3 @@ const OPERAND = 'operand' | ||
const c = expr.charAt(i) | ||
if ('\\' === c) { | ||
if ('\\' === c && !isEscaped) { | ||
isEscaped = true | ||
@@ -175,3 +175,3 @@ } else { | ||
public toString() { | ||
return this.value.replace(/\(/g, '\\(').replace(/\)/g, '\\)') | ||
return this.value.replace(/\\/g, '\\\\').replace(/\(/g, '\\(').replace(/\)/g, '\\)') | ||
} | ||
@@ -178,0 +178,0 @@ } |
@@ -20,2 +20,9 @@ import assert from 'assert' | ||
], | ||
['a\\\\ and b', '( a\\\\ and b )'], | ||
['\\a and b', '( a and b )'], | ||
['a\\ and b', '( a and b )'], | ||
['a and b\\', '( a and b )'], | ||
['( a and b\\\\)', '( a and b\\\\ )'], | ||
['a\\\\\\( and b\\\\\\)', '( a\\\\\\( and b\\\\\\) )'], | ||
['(a and \\b)', '( a and b )'], | ||
// a or not b | ||
@@ -93,3 +100,25 @@ ] | ||
}) | ||
it('evaluates expressions with escaped backslash', function () { | ||
const expr = parse('x\\\\ or(y\\\\\\)) or(z\\\\)') | ||
assert.strictEqual(expr.evaluate([]), false) | ||
assert.strictEqual(expr.evaluate(['x\\']), true) | ||
assert.strictEqual(expr.evaluate(['y\\)']), true) | ||
assert.strictEqual(expr.evaluate(['z\\']), true) | ||
assert.strictEqual(expr.evaluate(['x']), false) | ||
assert.strictEqual(expr.evaluate(['y)']), false) | ||
assert.strictEqual(expr.evaluate(['z']), false) | ||
}) | ||
it('evaluates expressions with backslash', function () { | ||
const expr = parse('\\x or y\\ or z\\') | ||
assert.strictEqual(expr.evaluate([]), false) | ||
assert.strictEqual(expr.evaluate(['x']), true) | ||
assert.strictEqual(expr.evaluate(['y']), true) | ||
assert.strictEqual(expr.evaluate(['z']), true) | ||
assert.strictEqual(expr.evaluate(['\\x']), false) | ||
assert.strictEqual(expr.evaluate(['y\\']), false) | ||
assert.strictEqual(expr.evaluate(['z\\']), false) | ||
}) | ||
}) | ||
}) |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
67581
671