Skip to content

Commit 6d282ee

Browse files
jamietannapaulRbr
authored andcommitted
deps: upgrade jsonpathly to 3.0.0
As part of [0], it was noted that the upstream library we use for JSON Path expressions isn't fully RFC 9535 compliant. Jammie took help from Claude Sonnet 4.5 to help diagnose a change in the public API for jsonpathly, where a single quoted path is returned. Paulr rewrote the code for better readability (and replace only first and last single quotes instead of all quotes) Co-authored-by: Paul B. <paulr@bump.sh> [0]: atamano/jsonpathly#12
1 parent 38862b8 commit 6d282ee

File tree

3 files changed

+25
-35
lines changed

3 files changed

+25
-35
lines changed

package-lock.json

Lines changed: 12 additions & 28 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)