Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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 @@ -83,6 +83,7 @@ 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 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)
- 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)
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 https:// prefix to URLs starting with www. to make them absolute
if (trimmedUrl.startsWith("www.")) {
trimmedUrl = "https://" + trimmedUrl;
}

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
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,12 @@ private static Stream<Arguments> stringsToParseTest() throws MalformedURLExcepti
List.of(),
""
),

// URL starting with www. (without protocol)
Arguments.of(
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"
),

// correct input
Arguments.of(
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 https://
URL result = URLUtil.create("www.example.com");
assertNotNull(result);
assertEquals("https://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