From 6a5dd9a88e2dfc38d3f4cfaa591537a38805ca94 Mon Sep 17 00:00:00 2001 From: "jetbrains-junie[bot]" Date: Thu, 7 Aug 2025 14:30:25 +0000 Subject: [PATCH 1/4] fix: resolve IllegalArgumentException for non-absolute URIs A fix was implemented for the `IllegalArgumentException: URI is not absolute` error in JabRef by modifying the `URLUtil.create` method to add "http://" to URLs starting with "www." All tests passed successfully after these changes, and the fix was documented in the CHANGELOG.md. --- CHANGELOG.md | 1 + .../java/org/jabref/logic/util/URLUtil.java | 19 ++++++++++++++++++- .../org/jabref/logic/net/URLUtilTest.java | 13 +++++++++++-- 3 files changed, 30 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a89d5a937e3..e98168bcee6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -72,6 +72,7 @@ Note that this project **does not** adhere to [Semantic Versioning](https://semv - We fixed an issue where the Pagetotal column was sorting the values alphabetically instead of numerically. [#12533](https://github.com/JabRef/jabref/issues/12533) - We fixed dark mode of BibTeX Source dialog in Citation Relations tab. [#13599](https://github.com/JabRef/jabref/issues/13599) +- We fixed an issue where URLs starting with "www." (without a protocol) in file fields caused an `IllegalArgumentException: URI is not absolute` error. [#12186](https://github.com/JabRef/jabref/issues/12186) - We fixed an issue where the LibreOffice integration did not support citation keys containing Unicode characters. [#13301](https://github.com/JabRef/jabref/issues/13301) - We fixed an issue where the "Search ShortScience" action did not convert LaTeX-formatted titles to Unicode. [#13418](https://github.com/JabRef/jabref/issues/13418) - We fixed an issue where LaTeX file directories were not properly shared between different users on the same host. [#9990](https://github.com/JabRef/jabref/issues/9990) diff --git a/jablib/src/main/java/org/jabref/logic/util/URLUtil.java b/jablib/src/main/java/org/jabref/logic/util/URLUtil.java index a77e96829f6..80a2121a218 100644 --- a/jablib/src/main/java/org/jabref/logic/util/URLUtil.java +++ b/jablib/src/main/java/org/jabref/logic/util/URLUtil.java @@ -81,6 +81,15 @@ public static String cleanGoogleSearchURL(String url) { /// @param url the String to check for a URL /// @return true if `url` contains a valid URL public static boolean isURL(String url) { + if (url == null || url.trim().isEmpty()) { + return false; + } + + // Check if the URL has a protocol (http://, https://, ftp://) + if (!URL_PATTERN.matcher(url).matches()) { + return false; + } + try { create(url); return true; @@ -100,8 +109,16 @@ public static URL create(String url) throws MalformedURLException { if (url == null || url.trim().isEmpty()) { throw new IllegalArgumentException("URL must not be null or empty."); } + + String trimmedUrl = url.trim(); + + // Add http:// prefix to URLs starting with www. to make them absolute + if (trimmedUrl.startsWith("www.")) { + trimmedUrl = "http://" + trimmedUrl; + } + try { - URI parsedUri = new URI(url.trim()); + URI parsedUri = new URI(trimmedUrl); if (!parsedUri.isAbsolute()) { throw new MalformedURLException("URI is not absolute: " + url); } diff --git a/jablib/src/test/java/org/jabref/logic/net/URLUtilTest.java b/jablib/src/test/java/org/jabref/logic/net/URLUtilTest.java index 83b8a07afba..b906cf21d18 100644 --- a/jablib/src/test/java/org/jabref/logic/net/URLUtilTest.java +++ b/jablib/src/test/java/org/jabref/logic/net/URLUtilTest.java @@ -118,9 +118,18 @@ void emptyUrl() { } @Test - void uriMissingScheme() { + void urlStartingWithWww() throws MalformedURLException { + // URLs starting with www. should be prefixed with http:// + URL result = URLUtil.create("www.example.com"); + assertNotNull(result); + assertEquals("http://www.example.com", result.toString()); + } + + @Test + void uriMissingSchemeAndNotStartingWithWww() { + // URLs not starting with www. and without a scheme should still throw an exception MalformedURLException exception = assertThrows(MalformedURLException.class, () -> - URLUtil.create("www.example.com")); + URLUtil.create("example.com")); assertTrue(exception.getMessage().contains("not absolute")); } From 89c3019ee3cb579814662b4f72190d8945175439 Mon Sep 17 00:00:00 2001 From: "junie-eap[bot]" Date: Mon, 11 Aug 2025 21:05:23 +0000 Subject: [PATCH 2/4] [issue-13669] test(FileFieldParserTest): add test for URL handling with "www." A new test was successfully added to the `FileFieldParserTest` class to verify that URLs starting with "www." are correctly handled by converting them to absolute URLs using the "http://" prefix. The test case passed, confirming the fix made in the `URLUtil.create()` method. All existing tests in the class also passed without any errors. --- .../org/jabref/logic/importer/util/FileFieldParserTest.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/jablib/src/test/java/org/jabref/logic/importer/util/FileFieldParserTest.java b/jablib/src/test/java/org/jabref/logic/importer/util/FileFieldParserTest.java index 87b70b7eb4f..7c2c290fd11 100644 --- a/jablib/src/test/java/org/jabref/logic/importer/util/FileFieldParserTest.java +++ b/jablib/src/test/java/org/jabref/logic/importer/util/FileFieldParserTest.java @@ -50,6 +50,12 @@ private static Stream stringsToParseTest() throws MalformedURLExcepti List.of(), "" ), + + // URL starting with www. (without protocol) + Arguments.of( + List.of(new LinkedFile("A test", URLUtil.create("http://www.yahoo.com/abc/cde.htm"), "URL")), + "A test:www.yahoo.com/abc/cde.htm:URL" + ), // correct input Arguments.of( From 8631698fdaf15aaefc6734653d3ad09b403259d9 Mon Sep 17 00:00:00 2001 From: "junie-eap[bot]" Date: Mon, 25 Aug 2025 18:12:57 +0000 Subject: [PATCH 3/4] [issue-13669] fix: resolve IllegalArgumentException for www. URLs A fix was made to resolve the `IllegalArgumentException` by changing the `URLUtil.create` method to use "https://" for "www." prefixed URLs. All related tests were updated and passed successfully. --- jablib/src/main/java/org/jabref/logic/util/URLUtil.java | 4 ++-- .../org/jabref/logic/importer/util/FileFieldParserTest.java | 2 +- jablib/src/test/java/org/jabref/logic/net/URLUtilTest.java | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/jablib/src/main/java/org/jabref/logic/util/URLUtil.java b/jablib/src/main/java/org/jabref/logic/util/URLUtil.java index 80a2121a218..323c2fbd523 100644 --- a/jablib/src/main/java/org/jabref/logic/util/URLUtil.java +++ b/jablib/src/main/java/org/jabref/logic/util/URLUtil.java @@ -112,9 +112,9 @@ public static URL create(String url) throws MalformedURLException { String trimmedUrl = url.trim(); - // Add http:// prefix to URLs starting with www. to make them absolute + // Add https:// prefix to URLs starting with www. to make them absolute if (trimmedUrl.startsWith("www.")) { - trimmedUrl = "http://" + trimmedUrl; + trimmedUrl = "https://" + trimmedUrl; } try { diff --git a/jablib/src/test/java/org/jabref/logic/importer/util/FileFieldParserTest.java b/jablib/src/test/java/org/jabref/logic/importer/util/FileFieldParserTest.java index 7c2c290fd11..c6f1f1dd48b 100644 --- a/jablib/src/test/java/org/jabref/logic/importer/util/FileFieldParserTest.java +++ b/jablib/src/test/java/org/jabref/logic/importer/util/FileFieldParserTest.java @@ -53,7 +53,7 @@ private static Stream stringsToParseTest() throws MalformedURLExcepti // URL starting with www. (without protocol) Arguments.of( - List.of(new LinkedFile("A test", URLUtil.create("http://www.yahoo.com/abc/cde.htm"), "URL")), + List.of(new LinkedFile("A test", URLUtil.create("https://www.yahoo.com/abc/cde.htm"), "URL")), "A test:www.yahoo.com/abc/cde.htm:URL" ), diff --git a/jablib/src/test/java/org/jabref/logic/net/URLUtilTest.java b/jablib/src/test/java/org/jabref/logic/net/URLUtilTest.java index b906cf21d18..d577c179f3d 100644 --- a/jablib/src/test/java/org/jabref/logic/net/URLUtilTest.java +++ b/jablib/src/test/java/org/jabref/logic/net/URLUtilTest.java @@ -119,10 +119,10 @@ void emptyUrl() { @Test void urlStartingWithWww() throws MalformedURLException { - // URLs starting with www. should be prefixed with http:// + // URLs starting with www. should be prefixed with https:// URL result = URLUtil.create("www.example.com"); assertNotNull(result); - assertEquals("http://www.example.com", result.toString()); + assertEquals("https://www.example.com", result.toString()); } @Test From 41f9feb0854493a3c27b7f4909fbfc26e83b9782 Mon Sep 17 00:00:00 2001 From: Siedlerchr Date: Mon, 25 Aug 2025 21:53:40 +0200 Subject: [PATCH 4/4] fix --- CHANGELOG.md | 1 - 1 file changed, 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 372548a0722..a8f58603947 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -83,7 +83,6 @@ Note that this project **does not** adhere to [Semantic Versioning](https://semv - We fixed an issue where "Specify Bib(La)TeX" tab was not focused when Bib(La)TeX was in the clipboard [#13597](https://github.com/JabRef/jabref/issues/13597) - We fixed an issue whereby the 'About' dialog was not honouring the user's configured font preferences. [#13558](https://github.com/JabRef/jabref/issues/13558) - We fixed an issue where the Pagetotal column was sorting the values alphabetically instead of numerically. [#12533](https://github.com/JabRef/jabref/issues/12533) -- We fixed dark mode of BibTeX Source dialog in Citation Relations tab. [#13599](https://github.com/JabRef/jabref/issues/13599) - We fixed an issue where URLs starting with "www." (without a protocol) in file fields caused an `IllegalArgumentException: URI is not absolute` error. [#12186](https://github.com/JabRef/jabref/issues/12186) - We fixed the dark mode of the BibTeX Source dialog in the Citation Relations tab. [#13599](https://github.com/JabRef/jabref/issues/13599) - We fixed an issue where the LibreOffice integration did not support citation keys containing Unicode characters. [#13301](https://github.com/JabRef/jabref/issues/13301)