Skip to content

Commit

Permalink
Sanitize URLs in file fields to handle invalid pipe characters ('|') C…
Browse files Browse the repository at this point in the history
…loses JabRef#11876.

- Introduced URLUtil.createUri() and URLUtil.create() to handle URL sanitization.
- Replaced direct calls to URI.create() and URI.create().toURL() with the new utility methods.
- URLs containing the pipe character ('|') are now properly encoded as '%7C' to prevent parsing errors.
- Added test cases to URLUtilTest to verify correct sanitization and URL creation.
- Added @archtest to ensure that the URI.create() method is not directly called in the codebase.
  • Loading branch information
hitalo-siriano committed Nov 17, 2024
1 parent 3551dc2 commit 2f390d4
Showing 1 changed file with 2 additions and 5 deletions.
7 changes: 2 additions & 5 deletions src/main/java/org/jabref/gui/fieldeditors/URLUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,7 @@ public static boolean isURL(String url) {
try {
URLUtil.create(url);
return true;
} catch (
MalformedURLException |
IllegalArgumentException e) {
} catch (MalformedURLException | IllegalArgumentException e) {
return false;
}
}
Expand All @@ -102,8 +100,7 @@ public static Optional<String> getSuffix(final String link, ExternalApplications
if ((url.getQuery() != null) && (url.getQuery().length() < (link.length() - 1))) {
strippedLink = link.substring(0, link.length() - url.getQuery().length() - 1);
}
} catch (
MalformedURLException e) {
} catch (MalformedURLException e) {
// Don't report this error, since this getting the suffix is a non-critical
// operation, and this error will be triggered and reported elsewhere.
}
Expand Down

0 comments on commit 2f390d4

Please sign in to comment.