0z5a opened a new issue, #20326:
URL: https://github.com/apache/pinot/issues/20326
URL scalar functions decode the query before splitting it, so escaped `&`,
`=` and `/` become real separators.
### What happens
`extractURLParameter`, `extractURLParameters` and `extractURLParameterNames`
split `URI.getQuery()` on `&` and `=`. `getQuery()` has already decoded the
`%XX` escapes, so a `%26` or `%3D` inside a value is split as if it were a
separator.
```sql
SELECT extractURLParameter(
'https://example.com/landing?redirect=https%3A%2F%2Fshop.example.org%2Fcart%3Fitem%3D42%26qty%3D2&utm_source=mail',
'redirect')
-- returns https://shop.example.org/cart?item=42
-- expected https://shop.example.org/cart?item=42&qty=2
SELECT extractURLParameter('...same URL...', 'qty')
-- returns 2 (there is no top-level qty parameter)
SELECT
extractURLParameter('https://example.com/search?q=rock%26roll&page=2', 'q')
-- returns rock
-- expected rock&roll
```
`cutWWW`, `cutQueryString`, `cutFragment`, `cutQueryStringAndFragment` and
`cutURLParameter` rebuild the URL with the multi-argument `java.net.URI`
constructor from the decoded components. That constructor quotes illegal
characters but does not escape `&`, `=`, `/` or `?` again, so the result is a
different URL:
```sql
SELECT cutURLParameter('https://example.com/search?q=rock%26roll&page=2',
'page')
-- returns https://example.com/search?q=rock&roll
-- expected https://example.com/search?q=rock%26roll
SELECT
cutFragment('https://example.com/landing?redirect=https%3A%2F%2Fshop.example.org%2Fcart%3Fitem%3D42%26qty%3D2#top')
-- returns
https://example.com/landing?redirect=https://shop.example.org/cart?item=42&qty=2
-- expected
https://example.com/landing?redirect=https%3A%2F%2Fshop.example.org%2Fcart%3Fitem%3D42%26qty%3D2
SELECT cutQueryString('https://example.com/files/a%2Fb?x=1')
-- returns https://example.com/files/a/b
-- expected https://example.com/files/a%2Fb
```
The `cut*` output also rewrites other escapes: `%41` becomes `A`, `%C3%A9`
becomes `é`, and an invalid UTF-8 escape such as `%FF` becomes `�`.
### Expected
Split the raw query (`getRawQuery()`) on `&` and `=` first, then decode each
key and value. The `cut*` functions should keep the parts of the URL they do
not remove exactly as they were.
### Version
Current `master` (the logic in `UrlFunctions.java` has not changed since
#14646). I reproduced it by calling `UrlFunctions` directly on macOS with a
recent JDK; nothing in it depends on the OS.
--
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]