0z5a opened a new pull request, #20327: URL: https://github.com/apache/pinot/pull/20327
Label: `bugfix` (I can't set labels on this repo). Since the `cut*` output changes for URLs with escapes, `backward-incompat` may fit as well; I'll leave that to you. ## Summary Fixes #20326. The URL scalar functions read the decoded query from `URI.getQuery()` and then split it on `&` and `=`, so an escaped `%26` or `%3D` inside a value (for example an encoded redirect URL) is split as a real separator. The `cut*` functions also rebuild the URL from decoded components with the multi-argument `URI` constructor, which does not escape `&`, `=`, `/` or `?` again, so they return a different URL than the one they were given. ## Fix - `extractURLParameter`, `extractURLParameters` and `extractURLParameterNames` split `getRawQuery()` and decode each key and value afterwards. The decoding matches `URI.getQuery()` (it keeps `+` as is), so the output is the same as before for any query without an escaped `&` or `=`. - `cutWWW`, `cutQueryString`, `cutFragment`, `cutQueryStringAndFragment` and `cutURLParameter` rebuild the URL from the raw components (`getRawAuthority()`, `getRawPath()`, `getRawQuery()`, `getRawFragment()`), so everything they do not remove is kept exactly as it was. `cutWWW` removes `www.` from the raw authority, after the user info if there is one. - `cutURLParameter` still decodes each key before comparing it with the name, as before. - Opaque URLs such as `mailto:` are returned unchanged, as before. One more change in behaviour, from the same rebuild: when `java.net.URI` accepts an authority but cannot parse a host from it (for example `http://my_host/p?a=1`, since `_` is not allowed in a host name), the `cut*` functions used to drop the authority and return `http:/p?a=1`. They now keep it: `http://my_host/p`. ## How I found it I was reading the URL functions and noticed that the `extract*` functions split the already decoded query. I then checked the `cut*` functions with URLs that carry an encoded URL in a parameter, which is common for redirect and tracking links. ## Where this can show up in practice This is my estimate; I have not seen a field report. - Clickstream or web-log tables where URLs carry an encoded URL in a parameter, such as `redirect=`, `return_to=` or `url=` on login, redirect and ad click links. `extractURLParameter(url, 'redirect')` returns a cut-off URL, and `extractURLParameter(url, name)` can return a value for a parameter that only exists inside the nested URL. - Search pages and filters with values that contain `&` or `=`, like `q=rock%26roll`. - Queries that use `cutURLParameter`, `cutQueryString` or `cutWWW` to normalize URLs for grouping or joins: the rewritten URL no longer matches the original string, and URLs that differ only in escaping can end up grouped together. ## Tests `UrlFunctionsTest.testEncodedSeparatorsInQuery` covers the three `extract*` functions with an encoded redirect URL and with `%26` and `%3D` in a key and a value, `+` and `%XX` decoding, and all five `cut*` functions with `%2F`, `%26` and `%C3%A9` in the path, query and fragment, including user info and a port in `cutWWW`, plus a `mailto:` URL. ## Testing Done - macOS, JDK 27: `UrlFunctionsTest` (all 30 tests) compiled on its own against TestNG with only `UrlFunctions` and a stub of the `@ScalarFunction` annotation; all pass. On `master` the new test fails with `expected [https://shop.example.org/cart?item=42&qty=2] but found [https://shop.example.org/cart?item=42]`. - I compared the old and new code on about 90 URLs, mostly the existing test inputs plus encoded ones, over all the URL functions and a few parameter names. All 122 differences out of 2,697 results come from escapes that are now kept or decoded after splitting, or from the `my_host` case above. For URLs without escapes the output is unchanged, apart from the `my_host` case. - `./mvnw spotless:apply`, `checkstyle:check`, `license:check` and `spotless:check` on `pinot-common`: pass. - Outside `UrlFunctionsTest`, the only reference to these functions in the repo is `udf-test-results/all-functions.yaml`, which lists their names but no outputs, so no other expectations need updating. - Not run: the full `pinot-common` build and test suite, and the integration tests (I worked from a partial checkout). -- 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]
