File tree Expand file tree Collapse file tree 2 files changed +35
-2
lines changed
Expand file tree Collapse file tree 2 files changed +35
-2
lines changed Original file line number Diff line number Diff line change @@ -83,8 +83,12 @@ class Query extends URL {
8383 }
8484 // regular select
8585 let alias = '' ; let field ; let cast = '' ; let subfields = [ ]
86- if ( k . includes ( ':' ) ) {
87- [ alias , field ] = k . split ( ':' )
86+ if ( / ^ [ ^ " ] * : / . test ( k ) ) {
87+ // first `:` is outside quotes
88+ [ alias , field ] = k . split ( / : ( .+ ) / )
89+ } else if ( / ^ " .* [ ^ \\ ] " : / . test ( k ) ) {
90+ // quoted alias
91+ [ alias , field ] = k . split ( / (?< = [ ^ \\ ] " ) : ( .+ ) / )
8892 } else {
8993 field = k
9094 }
Original file line number Diff line number Diff line change @@ -228,6 +228,35 @@ describe('Query', () => {
228228 }
229229 }
230230 } , 'select=id,jd:json_data::text,bt:json_data->blood_type::integer' )
231+
232+ itt ( 'json field with quoted key' , {
233+ select : {
234+ 'some->nested->"https://json-that-needs-quotes"' : true
235+ }
236+ } , 'select=some->nested->"https://json-that-needs-quotes"' )
237+
238+ itt ( 'json field with quoted key and aliased' , {
239+ select : {
240+ 'alias:some->nested->"https://json-that-needs-quotes"' : true
241+ }
242+ } , 'select=alias:some->nested->"https://json-that-needs-quotes"' )
243+
244+ itt ( 'json field with quoted nested key' , {
245+ select : {
246+ some : {
247+ nested : {
248+ '"https://json-that-needs-quotes"' : true
249+ }
250+ }
251+ }
252+ } , 'select=some->nested->"https://json-that-needs-quotes"'
253+ )
254+
255+ itt ( 'should parse quoted aliases with escaped quotes properly' , {
256+ select : {
257+ '"a:\\":b":"x:y:z"' : true
258+ }
259+ } , 'select="a:\\":b":"x:y:z"' )
231260 } )
232261
233262 describe ( 'ordering' , ( ) => {
You can’t perform that action at this time.
0 commit comments