Skip to content

Commit 030e954

Browse files
committed
fix: avoid treating at sign within regex as current context; fixes #280
1 parent 6451f7e commit 030e954

11 files changed

Lines changed: 37 additions & 16 deletions

‎badges/tests-badge.svg‎

Lines changed: 1 addition & 1 deletion
Loading

‎dist/index-browser-esm.js‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2382,8 +2382,10 @@ class JSONPathClass {
23822382
if (!scriptCache.has(scriptCacheKey)) {
23832383
let script = code.replaceAll('@parentProperty', '_$_parentProperty').replaceAll('@parent', '_$_parent').replaceAll('@property', '_$_property').replaceAll('@root', '_$_root')
23842384
// Replace a bare `@` (not followed by an identifier
2385-
// character) while leaving quoted string literals intact
2386-
.replaceAll(/('(?:\\.|[^'\\])*'|"(?:\\.|[^"\\])*")|@(?![\w$])/gv, (_, str) => str ?? '_$_v');
2385+
// character) while leaving quoted string literals and
2386+
// regex literals (a `/` where an operand is expected,
2387+
// as opposed to division) intact
2388+
.replaceAll(/('(?:\\.|[^'\\])*'|"(?:\\.|[^"\\])*"|(?:^|[\(,=:\[!\|?\{\};+\-*%<>~^]|&)\s*\/(?:\\.|\[(?:\\.|[^\]\\])*\]|[^\/\\\[])+\/[dgimsuvy]*)|@(?![\w$])/gv, (_, literal) => literal ?? '_$_v');
23872389
if (containsPath) {
23882390
script = script.replaceAll('@path', '_$_path');
23892391
}

‎dist/index-browser-esm.min.js‎

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎dist/index-browser-esm.min.js.map‎

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎dist/index-browser-umd.cjs‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2388,8 +2388,10 @@
23882388
if (!scriptCache.has(scriptCacheKey)) {
23892389
let script = code.replaceAll('@parentProperty', '_$_parentProperty').replaceAll('@parent', '_$_parent').replaceAll('@property', '_$_property').replaceAll('@root', '_$_root')
23902390
// Replace a bare `@` (not followed by an identifier
2391-
// character) while leaving quoted string literals intact
2392-
.replaceAll(/('(?:\\.|[^'\\])*'|"(?:\\.|[^"\\])*")|@(?![\w$])/gv, (_, str) => str ?? '_$_v');
2391+
// character) while leaving quoted string literals and
2392+
// regex literals (a `/` where an operand is expected,
2393+
// as opposed to division) intact
2394+
.replaceAll(/('(?:\\.|[^'\\])*'|"(?:\\.|[^"\\])*"|(?:^|[\(,=:\[!\|?\{\};+\-*%<>~^]|&)\s*\/(?:\\.|\[(?:\\.|[^\]\\])*\]|[^\/\\\[])+\/[dgimsuvy]*)|@(?![\w$])/gv, (_, literal) => literal ?? '_$_v');
23932395
if (containsPath) {
23942396
script = script.replaceAll('@path', '_$_path');
23952397
}

‎dist/index-browser-umd.min.cjs‎

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

‎dist/index-browser-umd.min.cjs.map‎

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎dist/index-node-cjs.cjs‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2386,8 +2386,10 @@ class JSONPathClass {
23862386
if (!scriptCache.has(scriptCacheKey)) {
23872387
let script = code.replaceAll('@parentProperty', '_$_parentProperty').replaceAll('@parent', '_$_parent').replaceAll('@property', '_$_property').replaceAll('@root', '_$_root')
23882388
// Replace a bare `@` (not followed by an identifier
2389-
// character) while leaving quoted string literals intact
2390-
.replaceAll(/('(?:\\.|[^'\\])*'|"(?:\\.|[^"\\])*")|@(?![\w$])/gv, (_, str) => str ?? '_$_v');
2389+
// character) while leaving quoted string literals and
2390+
// regex literals (a `/` where an operand is expected,
2391+
// as opposed to division) intact
2392+
.replaceAll(/('(?:\\.|[^'\\])*'|"(?:\\.|[^"\\])*"|(?:^|[\(,=:\[!\|?\{\};+\-*%<>~^]|&)\s*\/(?:\\.|\[(?:\\.|[^\]\\])*\]|[^\/\\\[])+\/[dgimsuvy]*)|@(?![\w$])/gv, (_, literal) => literal ?? '_$_v');
23912393
if (containsPath) {
23922394
script = script.replaceAll('@path', '_$_path');
23932395
}

‎dist/index-node-esm.js‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2384,8 +2384,10 @@ class JSONPathClass {
23842384
if (!scriptCache.has(scriptCacheKey)) {
23852385
let script = code.replaceAll('@parentProperty', '_$_parentProperty').replaceAll('@parent', '_$_parent').replaceAll('@property', '_$_property').replaceAll('@root', '_$_root')
23862386
// Replace a bare `@` (not followed by an identifier
2387-
// character) while leaving quoted string literals intact
2388-
.replaceAll(/('(?:\\.|[^'\\])*'|"(?:\\.|[^"\\])*")|@(?![\w$])/gv, (_, str) => str ?? '_$_v');
2387+
// character) while leaving quoted string literals and
2388+
// regex literals (a `/` where an operand is expected,
2389+
// as opposed to division) intact
2390+
.replaceAll(/('(?:\\.|[^'\\])*'|"(?:\\.|[^"\\])*"|(?:^|[\(,=:\[!\|?\{\};+\-*%<>~^]|&)\s*\/(?:\\.|\[(?:\\.|[^\]\\])*\]|[^\/\\\[])+\/[dgimsuvy]*)|@(?![\w$])/gv, (_, literal) => literal ?? '_$_v');
23892391
if (containsPath) {
23902392
script = script.replaceAll('@path', '_$_path');
23912393
}

‎src/jsonpath.js‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1048,10 +1048,12 @@ class JSONPathClass {
10481048
.replaceAll('@property', '_$_property')
10491049
.replaceAll('@root', '_$_root')
10501050
// Replace a bare `@` (not followed by an identifier
1051-
// character) while leaving quoted string literals intact
1051+
// character) while leaving quoted string literals and
1052+
// regex literals (a `/` where an operand is expected,
1053+
// as opposed to division) intact
10521054
.replaceAll(
1053-
/('(?:\\.|[^'\\])*'|"(?:\\.|[^"\\])*")|@(?![\w$])/gv,
1054-
(_, str) => str ?? '_$_v'
1055+
/('(?:\\.|[^'\\])*'|"(?:\\.|[^"\\])*"|(?:^|[\(,=:\[!\|?\{\};+\-*%<>~^]|&)\s*\/(?:\\.|\[(?:\\.|[^\]\\])*\]|[^\/\\\[])+\/[dgimsuvy]*)|@(?![\w$])/gv,
1056+
(_, literal) => literal ?? '_$_v'
10551057
);
10561058
if (containsPath) {
10571059
script = script.replaceAll('@path', '_$_path');

0 commit comments

Comments
 (0)