-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Refine error message in URLUtil::create #13337
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
Conversation
|
please don't always open a new pr this creates noise for us, just push your change to your branch, the pr gets updated automatically |
|
Tests are missing - see https://github.com/JabRef/jabref/pull/12800/files for example tests. |
|
About the PR description: Do not put your code changes in there. Put it into the code. This is what the git diff in github is for. |
|
If I put . or / then the cases will failed, so what is the solution for this. |
|
@jenilpatel264 please try to avoid using AI if you don't know what you are doing. It will not help you learn. |
|
@trag-bot didn't find any issues in the code! ✅✨ |
koppor
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know if this really fixes the issue as when called www.example.org. there was another issue where the file field contained a URL without protocol...
* upstream/main: (47 commits) Adapt some fetcher tests (JabRef#13370) change template issue number (JabRef#13367) Refine error message in URLUtil::create (JabRef#13337) fix deletion again (JabRef#13369) Only prevent failure in publishing from stopping the workflow (JabRef#13368) Refactor "enableFileAnnotationsTab" to "smartFileAnnotationsTab" and rewrote shouldShow in FileAnnotationTab as requested in JabRef#13279 (JabRef#13338) fix workflow (JabRef#13366) Fixamd64linux (JabRef#13365) Only delete for arm64 (JabRef#13364) New Crowdin updates (JabRef#13363) Bump org.junit.jupiter:junit-jupiter-api in /versions (JabRef#13362) Bump org.apache.logging.log4j:log4j-to-slf4j in /versions (JabRef#13359) Bump com.github.javaparser:javaparser-symbol-solver-core in /versions (JabRef#13361) Bump org.junit.platform:junit-platform-launcher in /versions (JabRef#13360) Bump com.fasterxml.jackson.datatype:jackson-datatype-jsr310 in /versions (JabRef#13358) Gradle build updates (JabRef#13319) Add "Disable GitHub actions" (JabRef#13356) Make jabref host executable on mac and on linux and fix import command line argument (JabRef#13355) Delete .github/workflows/merge-upstream.yml (JabRef#13357) chore(deps): update dependency org.apache.logging.log4j:log4j-to-slf4j to v2.25.0 (JabRef#13353) ...
* upstream/main: (54 commits) Move publishing to maven central to a separate workflow (JabRef#13372) Add more guards to workflows not running on forked JabRef repos Copy real HTML from entry preview (JabRef#13339) Adapt some fetcher tests (JabRef#13370) change template issue number (JabRef#13367) Refine error message in URLUtil::create (JabRef#13337) fix deletion again (JabRef#13369) Only prevent failure in publishing from stopping the workflow (JabRef#13368) Refactor "enableFileAnnotationsTab" to "smartFileAnnotationsTab" and rewrote shouldShow in FileAnnotationTab as requested in JabRef#13279 (JabRef#13338) fix workflow (JabRef#13366) Fixamd64linux (JabRef#13365) Only delete for arm64 (JabRef#13364) New Crowdin updates (JabRef#13363) Bump org.junit.jupiter:junit-jupiter-api in /versions (JabRef#13362) Bump org.apache.logging.log4j:log4j-to-slf4j in /versions (JabRef#13359) Bump com.github.javaparser:javaparser-symbol-solver-core in /versions (JabRef#13361) Bump org.junit.platform:junit-platform-launcher in /versions (JabRef#13360) Bump com.fasterxml.jackson.datatype:jackson-datatype-jsr310 in /versions (JabRef#13358) Gradle build updates (JabRef#13319) Add "Disable GitHub actions" (JabRef#13356) ...
This PR closes #12186
Added comprehensive validation and exception handling to ensure robust URI parsing and conversion to a URL in the create method. This improves reliability and user feedback by explicitly handling malformed or incomplete URI inputs.
Description
This PR enhances the create method to handle edge cases where the URI is malformed, incomplete, or improperly structured. Previously, certain invalid inputs could lead to unclear exceptions. This implementation improves error clarity and stability.
Changes
File: src/main/java/org/jabref/logic/util/URLUtil.java
What: Enhanced the create method with multiple validation checks and detailed exception handling.
Why: To ensure that only valid, absolute URIs with proper scheme and host are converted to URLs and to prevent ambiguous or uncaught runtime exceptions.
Detailed Explanation
Validation Checks Added:
Null or Empty Input:
If the input url is null or an empty string (after trimming), a MalformedURLException is thrown with an appropriate message.
Absolute URI Check:
Ensures the parsed URI is absolute before attempting conversion to a URL.
Scheme and Host Validation:
Ensures that both the scheme (e.g., http, https) and host are present in the URI.
Improved Exception Handling:
URISyntaxException: Catches invalid URI syntax and wraps it in a MalformedURLException with a detailed message.
IllegalArgumentException: Catches improper input such as illegal characters or encoding issues.
NullPointerException: Safeguards against unexpected null components in the URI.
Exception: Catches all other unforeseen issues during URI parsing or conversion.
Mandatory checks
CHANGELOG.mddescribed in a way that is understandable for the average user (if change is visible to the user)