jacktengg opened a new pull request, #68011:
URL: https://github.com/apache/doris/pull/68011

   ### What problem does this PR solve?
   
   Problem Summary:
   `parse_url(url, 'QUERY', key)` searched for the key in the whole (trimmed) 
url instead of only in the query component, so text belonging to the path or to 
the fragment was accepted as a query key.
   
   Reproduction:
   ```sql
   SELECT parse_url('http://h/p#f?k=v', 'QUERY', 'k');  -- returns 'v' 
(expected NULL)
   SELECT parse_url('http://h/p&k=v?x=1', 'QUERY', 'k'); -- returns 'v?x=1' 
(expected NULL)
   ```
   
   Root cause:
   `UrlParser::parse_url_key` scanned `trimmed_url` from the beginning and 
treated any `?`/`&` preceded match as a query key, so it never checked whether 
the match was inside the real query component. Two further defects existed in 
the same loop: a key at offset 0 of the search window (the first key of the 
query, or the first key after a `&`) was rejected, and a key value was not 
bounded by the fragment, so `#` was reported as part of the value.
   
   Fix:
   Locate the real query component first - it starts at the first `?` and ends 
at the `#` that starts the fragment - and reject urls whose `#` comes before 
the `?`. The key/value scan is now bounded by that component, recognizes the 
first key and advances past each candidate so that no text is visited twice.
   
   After the fix both statements above return NULL, and the first query 
parameter as well as duplicated keys (`?k=1&k=2` - the last one wins, as 
before) are handled correctly.
   
   ### Release note
   
   Fix `parse_url(url, 'QUERY', key)` returning values from the path or the 
fragment for urls that do not contain the requested key in the query.
   
   ### Check List (For Author)
   
   - Test: Regression test / Unit Test
       - New regression suite 
`regression-test/suites/function_p0/test_parse_url_key.groovy` (output 
generated with `run-regression-test.sh --run -d function_p0 -s 
test_parse_url_key -forceGenOut`, then re-run and passed).
       - Extended `be/test/exprs/function/function_url_test.cpp` with 
`ParseUrlQueryKeyTest`; `FunctionUrlTEST.*`, 
`function_string_test.function_parse_url_test` and 
`function_string_test.function_extract_url_parameter_test` all pass.
   - Behavior changed: Yes (see above, path/fragment text is no longer a query 
key)
   - Does this need documentation: No
   
   ### What problem does this PR solve?
   
   Issue Number: close #xxx
   
   Related PR: #xxx
   
   Problem Summary:
   
   ### Release note
   
   None
   
   ### Check List (For Author)
   
   - Test <!-- At least one of them must be included. -->
       - [ ] Regression test
       - [ ] Unit Test
       - [ ] Manual test (add detailed scripts or steps below)
       - [ ] No need to test or manual test. Explain why:
           - [ ] This is a refactor/code format and no logic has been changed.
           - [ ] Previous test can cover this change.
           - [ ] No code files have been changed.
           - [ ] Other reason <!-- Add your reason?  -->
   
   - Behavior changed:
       - [ ] No.
       - [ ] Yes. <!-- Explain the behavior change -->
   
   - Does this need documentation?
       - [ ] No.
       - [ ] Yes. <!-- Add document PR link here. eg: 
https://github.com/apache/doris-website/pull/1214 -->
   
   ### Check List (For Reviewer who merge this PR)
   
   - [ ] Confirm the release note
   - [ ] Confirm test cases
   - [ ] Confirm document
   - [ ] Add branch pick label <!-- Add branch pick label that this PR should 
merge into -->
   
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to