-
Notifications
You must be signed in to change notification settings - Fork 2.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
RuntimeException thrown instead of IllegalArgumentException when failing to decode URL #46197
Comments
/cc @FroMage (rest) |
Makes sense! Would you like to propose a PR? |
Sure! , i'll submit the PR , it would be my first so i'll probably take long to follow the contributing guidelines 🙏 |
It shouldn't be too long :) |
…L decoding Previously, URLUtils.decode threw a RuntimeException when encountering invalid percent-encoded values. Now, it throws an IllegalArgumentException, ensuring that malformed input is correctly recognized as a client error. Test coverage added for: - Invalid percent encoding (e.g., %zz, %2) - Gray-area invalid UTF-8 cases (e.g., %80) - Properly encoded values (e.g., %20, form-encoded +, Japanese characters) Fixes quarkusio#46197
…L decoding Previously, URLUtils.decode threw a RuntimeException when encountering invalid percent-encoded values. Now, it throws an IllegalArgumentException, ensuring that malformed input is correctly recognized as a client error. Test coverage added for: - Invalid percent encoding (e.g., %zz, %2) - Gray-area invalid UTF-8 cases (e.g., %80) - Properly encoded values (e.g., %20, form-encoded +, Japanese characters) Fixes quarkusio#46197
…L decoding Previously, URLUtils.decode threw a RuntimeException when encountering invalid percent-encoded values. Now, it throws an IllegalArgumentException, ensuring that malformed input is correctly recognized as a client error. Test coverage added for: - Invalid percent encoding (e.g., %zz, %2) - Gray-area invalid UTF-8 cases (e.g., %80) - Properly encoded values (e.g., %20, form-encoded +, Japanese characters) Fixes quarkusio#46197
…RL decoding Previously, URLUtils.decode threw a RuntimeException when encountering invalid percent-encoded values. Now, it throws an IllegalArgumentException, ensuring that malformed input is correctly recognized as a client error. Test coverage added for: - Invalid percent encoding (e.g., %zz, %2) - Gray-area invalid UTF-8 cases (e.g., %80) - Properly encoded values (e.g., %20, form-encoded +, Japanese characters) Fixes quarkusio#46197 (cherry picked from commit ed6ec4b)
I came across this because I have the same issue. I’m not sure how changing the exception type to Should it be throwing an instance of (I also have the same issue with decoding forms in Undertow servlets but I don’t think there’s an easy fix there because the exception flows through user code.) |
That does sounds reasonable, WDYT @FroMage ? |
Describe the bug
When making a request with an invalid parameter in the body—specifically, a non-decodable parameter—the exception thrown is a
RuntimeException
. However, according to the documentation here, the expected behavior is to throw anIllegalArgumentException
.Expected behavior
According to the code in URLUtils.decode, an IllegalArgumentException should be thrown when decoding an invalid parameter.
Actual behavior
When an invalid parameter is provided, the code calls FailedToDecodeURL, which throws a RuntimeException, leading to a
500 Internal Server Error
instead of a400 Bad Request
.How to Reproduce?
Short Version:
Run a Quarkus-based web server and send a request with a malformed, non-decodable parameter in the request body.
Long Version (Reproducing with Keycloak):
Output of
uname -a
orver
Linux fe9e37cde0ad 6.10.14-linuxkit #1 SMP Thu Oct 24 19:28:55 UTC 2024 aarch64 aarch64 aarch64 GNU/Linux
Output of
java -version
openjdk version "17.0.10" 2024-01-16 LTS OpenJDK Runtime Environment (Red_Hat-17.0.10.0.7-1) (build 17.0.10+7-LTS) OpenJDK 64-Bit Server VM (Red_Hat-17.0.10.0.7-1) (build 17.0.10+7-LTS, mixed mode)
Quarkus version or git rev
tested with 3.2.7.Final, also 3.8.5 and the code has not changed
Build tool (ie. output of
mvnw --version
orgradlew --version
)built with docker so not needed
Additional information
Why This Matters:
Suggested Fix
Modify URLUtils.failedToDecodeURL to throw an IllegalArgumentException instead of a RuntimeException.
Current Code:
Proposed Change:
The text was updated successfully, but these errors were encountered: