@@ -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