Skip to content

Commit 79a78d3

Browse files
jetbrains-junie[bot]junie-eap[bot]Siedlerchr
authored
[Junie]: fix: resolve IllegalArgumentException for non-absolute URIs (#13669)
* 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. * [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. * [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. * fix --------- Co-authored-by: jetbrains-junie[bot] <jetbrains-junie[bot]@users.noreply.github.com> Co-authored-by: junie-eap[bot] <junie-eap[bot]@users.noreply.github.com> Co-authored-by: Christoph <[email protected]>
1 parent 32a3c50 commit 79a78d3

File tree

4 files changed

+36
-3
lines changed

4 files changed

+36
-3
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ Note that this project **does not** adhere to [Semantic Versioning](https://semv
8484
- 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)
8585
- 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)
8686
- We fixed an issue where the Pagetotal column was sorting the values alphabetically instead of numerically. [#12533](https://github.com/JabRef/jabref/issues/12533)
87+
- 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)
8788
- We fixed the dark mode of the BibTeX Source dialog in the Citation Relations tab. [#13599](https://github.com/JabRef/jabref/issues/13599)
8889
- We fixed an issue where the LibreOffice integration did not support citation keys containing Unicode characters. [#13301](https://github.com/JabRef/jabref/issues/13301)
8990
- 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)

jablib/src/main/java/org/jabref/logic/util/URLUtil.java

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,15 @@ public static String cleanGoogleSearchURL(String url) {
8181
/// @param url the String to check for a URL
8282
/// @return true if `url` contains a valid URL
8383
public static boolean isURL(String url) {
84+
if (url == null || url.trim().isEmpty()) {
85+
return false;
86+
}
87+
88+
// Check if the URL has a protocol (http://, https://, ftp://)
89+
if (!URL_PATTERN.matcher(url).matches()) {
90+
return false;
91+
}
92+
8493
try {
8594
create(url);
8695
return true;
@@ -100,8 +109,16 @@ public static URL create(String url) throws MalformedURLException {
100109
if (url == null || url.trim().isEmpty()) {
101110
throw new IllegalArgumentException("URL must not be null or empty.");
102111
}
112+
113+
String trimmedUrl = url.trim();
114+
115+
// Add https:// prefix to URLs starting with www. to make them absolute
116+
if (trimmedUrl.startsWith("www.")) {
117+
trimmedUrl = "https://" + trimmedUrl;
118+
}
119+
103120
try {
104-
URI parsedUri = new URI(url.trim());
121+
URI parsedUri = new URI(trimmedUrl);
105122
if (!parsedUri.isAbsolute()) {
106123
throw new MalformedURLException("URI is not absolute: " + url);
107124
}

jablib/src/test/java/org/jabref/logic/importer/util/FileFieldParserTest.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,12 @@ private static Stream<Arguments> stringsToParseTest() throws MalformedURLExcepti
5050
List.of(),
5151
""
5252
),
53+
54+
// URL starting with www. (without protocol)
55+
Arguments.of(
56+
List.of(new LinkedFile("A test", URLUtil.create("https://www.yahoo.com/abc/cde.htm"), "URL")),
57+
"A test:www.yahoo.com/abc/cde.htm:URL"
58+
),
5359

5460
// correct input
5561
Arguments.of(

jablib/src/test/java/org/jabref/logic/net/URLUtilTest.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,9 +118,18 @@ void emptyUrl() {
118118
}
119119

120120
@Test
121-
void uriMissingScheme() {
121+
void urlStartingWithWww() throws MalformedURLException {
122+
// URLs starting with www. should be prefixed with https://
123+
URL result = URLUtil.create("www.example.com");
124+
assertNotNull(result);
125+
assertEquals("https://www.example.com", result.toString());
126+
}
127+
128+
@Test
129+
void uriMissingSchemeAndNotStartingWithWww() {
130+
// URLs not starting with www. and without a scheme should still throw an exception
122131
MalformedURLException exception = assertThrows(MalformedURLException.class, () ->
123-
URLUtil.create("www.example.com"));
132+
URLUtil.create("example.com"));
124133
assertTrue(exception.getMessage().contains("not absolute"));
125134
}
126135

0 commit comments

Comments
 (0)