Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
19 changes: 18 additions & 1 deletion jablib/src/main/java/org/jabref/logic/util/URLUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please update to https - we have 2025 with http severywhere. @jetbrains-junie

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please update to https - we have 2025 with http severywhere. https://github.com/jetbrains-junie

}

try {
URI parsedUri = new URI(url.trim());
URI parsedUri = new URI(trimmedUrl);
if (!parsedUri.isAbsolute()) {
throw new MalformedURLException("URI is not absolute: " + url);
}
Expand Down
13 changes: 11 additions & 2 deletions jablib/src/test/java/org/jabref/logic/net/URLUtilTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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"));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please keep the existin test - only add new ones @jetbrains-junie

URLUtil.create("example.com"));
assertTrue(exception.getMessage().contains("not absolute"));
}

Expand Down
Loading