Skip to content

Commit 478d949

Browse files
authored
Merge pull request #782 from jamietanna/fix/jsonpath
deps: upgrade jsonpathly to 3.0.0
2 parents 4ab0536 + 6d282ee commit 478d949

3 files changed

Lines changed: 20 additions & 23 deletions

File tree

package-lock.json

Lines changed: 7 additions & 16 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@
101101
"axios": "^1.7.7",
102102
"chalk": "^5.3.0",
103103
"debug": "^4.3.7",
104-
"jsonpathly": "^2.0.2",
104+
"jsonpathly": "^3.0.0",
105105
"mergician": "^2.0.2",
106106
"open": "^10.1.0"
107107
}

src/core/overlay.ts

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -86,12 +86,7 @@ export class Overlay {
8686

8787
// Take last element from path (which is the thing to act
8888
// upon)
89-
let thingToActUpon: number | string | undefined = explodedPath.pop()
90-
// The last element (e.g. '"price"]' or '0]') contains a final ']'
91-
// so we need to remove it AND we need to parse the element to
92-
// transform the string in either a string or a number
93-
thingToActUpon =
94-
thingToActUpon === undefined ? '$' : (thingToActUpon = JSON.parse(thingToActUpon.slice(0, -1)) as number | string)
89+
const thingToActUpon: number | string = this.pathEntryToKey(explodedPath.pop())
9590

9691
// Reconstruct the stringified path expression targeting the parent
9792
const parentPath: string = explodedPath.join('][')
@@ -117,6 +112,17 @@ export class Overlay {
117112
return action.description ? `Action '${action.description}'` : 'Action'
118113
}
119114

115+
// The last path entry (e.g. "'price']" or '0]') contains a final
116+
// ']' so we need to remove it AND we need to replace single quotes
117+
// to double quotes AND FINALLY parse the element to transform the
118+
// string in either a string or a number.
119+
private pathEntryToKey(pathEntry: string | undefined): number | string {
120+
if (pathEntry === undefined) {
121+
return '$'
122+
}
123+
return JSON.parse(pathEntry.slice(0, -1).replaceAll(/(^'|'$)/g, '"'))
124+
}
125+
120126
private remove(parent: JSONSchema4Object, property_or_index: number | string): void {
121127
if (Array.isArray(parent)) {
122128
parent.splice(property_or_index as number, 1)

0 commit comments

Comments
 (0)