@@ -31,6 +31,31 @@ describe('tokens_utils', () => {
3131 const result = removeTrailingWhitespaces ( url ) ;
3232 expect ( result ) . toBe ( url ) ;
3333 } ) ;
34+ it ( `doesn't treat a question mark inside quotes as query string start` , ( ) => {
35+ const url = '_search/"?literal" trailing_text' ;
36+ const result = removeTrailingWhitespaces ( url ) ;
37+ expect ( result ) . toBe ( '_search/"?literal"' ) ;
38+ } ) ;
39+ it ( `does not strip unquoted spaces inside query values (the reported bug case)` , ( ) => {
40+ const url = 'myindex/_search?q=type:organisation AND elastic' ;
41+ const result = removeTrailingWhitespaces ( url ) ;
42+ expect ( result ) . toBe ( url ) ;
43+ } ) ;
44+ it ( `still detects and strips inline comment after unquoted query spaces` , ( ) => {
45+ const url = 'myindex/_search?q=type:organisation AND elastic // filter orgs' ;
46+ const result = removeTrailingWhitespaces ( url ) ;
47+ expect ( result ) . toBe ( 'myindex/_search?q=type:organisation AND elastic' ) ;
48+ } ) ;
49+ it ( `still detects inline comment after mixed whitespace in query values` , ( ) => {
50+ const url = 'myindex/_search?q=type:organisation AND elastic \t// filter orgs' ;
51+ const result = removeTrailingWhitespaces ( url ) ;
52+ expect ( result ) . toBe ( 'myindex/_search?q=type:organisation AND elastic' ) ;
53+ } ) ;
54+ it ( `still detects and strips hash comment after unquoted query spaces` , ( ) => {
55+ const url = 'myindex/_search?q=type:organisation AND elastic # filter orgs' ;
56+ const result = removeTrailingWhitespaces ( url ) ;
57+ expect ( result ) . toBe ( 'myindex/_search?q=type:organisation AND elastic' ) ;
58+ } ) ;
3459 } ) ;
3560
3661 describe ( 'parseLine' , ( ) => {
@@ -48,6 +73,15 @@ describe('tokens_utils', () => {
4873 expect ( urlPathTokens ) . toEqual ( [ '_search' ] ) ;
4974 expect ( urlParamsTokens [ 0 ] ) . toEqual ( [ 'query' , '"test1 test2 test3"' ] ) ;
5075 } ) ;
76+ it ( 'preserves unquoted spaces inside query values' , ( ) => {
77+ const { method, url, urlPathTokens, urlParamsTokens } = parseLine (
78+ 'GET myindex/_search?q=type:organisation AND elastic'
79+ ) ;
80+ expect ( method ) . toBe ( 'GET' ) ;
81+ expect ( url ) . toBe ( 'myindex/_search?q=type:organisation AND elastic' ) ;
82+ expect ( urlPathTokens ) . toEqual ( [ 'myindex' , '_search' ] ) ;
83+ expect ( urlParamsTokens [ 0 ] ) . toEqual ( [ 'q' , 'type:organisation AND elastic' ] ) ;
84+ } ) ;
5185 it ( 'works with multiple whitespaces' , ( ) => {
5286 const { method, url, urlPathTokens, urlParamsTokens } = parseLine (
5387 ' GET _search?query="test1 test2 test3" // comment'
0 commit comments