File tree Expand file tree Collapse file tree 2 files changed +14
-10
lines changed
packages/client/src/openapi Expand file tree Collapse file tree 2 files changed +14
-10
lines changed Original file line number Diff line number Diff line change @@ -17,8 +17,13 @@ describe('bracketNotation', () => {
1717 expect ( serializer . parsePath ( 'a[b]c[d' ) ) . toEqual ( [ 'a[b]c[d' ] )
1818 expect ( serializer . parsePath ( 'a[[b]]' ) ) . toEqual ( [ 'a' , '[b]' ] )
1919 expect ( serializer . parsePath ( 'a\\[[b]]' ) ) . toEqual ( [ 'a[' , 'b]' ] )
20+ expect ( serializer . parsePath ( 'abc[]' ) ) . toEqual ( [ 'abc' , '' ] )
21+
2022 expect ( serializer . parsePath ( 'abc[def' ) ) . toEqual ( [ 'abc[def' ] )
21- expect ( serializer . parsePath ( 'abc[d][ef' ) ) . toEqual ( [ 'abc' , 'd][ef' ] )
23+ expect ( serializer . parsePath ( 'abc[d][ef' ) ) . toEqual ( [ 'abc[d][ef' ] )
24+ expect ( serializer . parsePath ( 'abc[d][' ) ) . toEqual ( [ 'abc[d][' ] )
25+ expect ( serializer . parsePath ( 'abc[' ) ) . toEqual ( [ 'abc[' ] )
26+ expect ( serializer . parsePath ( 'abc]' ) ) . toEqual ( [ 'abc]' ] )
2227 } )
2328
2429 it . each ( [
Original file line number Diff line number Diff line change @@ -112,20 +112,26 @@ export class BracketNotationSerializer {
112112 parsePath ( path : string ) : string [ ] {
113113 const segments : string [ ] = [ ]
114114
115+ let inBrackets = false
115116 let currentSegment = ''
116117 let backslashCount = 0
117118
118119 for ( let i = 0 ; i < path . length ; i ++ ) {
119120 const char = path [ i ] !
120121 const nextChar = path [ i + 1 ]
121122
122- if ( char === ']' && ( nextChar === undefined || nextChar === '[' ) && backslashCount % 2 === 0 ) {
123+ if ( inBrackets && char === ']' && ( nextChar === undefined || nextChar === '[' ) && backslashCount % 2 === 0 ) {
124+ if ( nextChar === undefined ) {
125+ inBrackets = false
126+ }
127+
123128 segments . push ( currentSegment )
124129 currentSegment = ''
125130 i ++
126131 }
127132
128133 else if ( segments . length === 0 && char === '[' && backslashCount % 2 === 0 ) {
134+ inBrackets = true
129135 segments . push ( currentSegment )
130136 currentSegment = ''
131137 }
@@ -140,14 +146,7 @@ export class BracketNotationSerializer {
140146 }
141147 }
142148
143- if ( ! segments . length ) {
144- segments . push ( currentSegment )
145- }
146- else if ( currentSegment ) {
147- segments [ segments . length - 1 ] += segments . length === 1 ? `[${ currentSegment } ` : `][${ currentSegment } `
148- }
149-
150- return segments
149+ return inBrackets || segments . length === 0 ? [ path ] : segments
151150 }
152151}
153152
You can’t perform that action at this time.
0 commit comments