Skip to content

Commit

Permalink
Allow encoded HTTP URL to create new entry (JabRef#11036)
Browse files Browse the repository at this point in the history
* Fix for Issue JabRef#10648

At org.jabref.model.entry.identifier.DOI#DOI, the method which the trimmedDoi is decoded has been modified in the case trimmedDoi being an HTTP URL.

* PR corrections

1)java.net.URLDecoder.decode(String, Charset) is now used
2)Tests from acceptEncodedDoiUrl moved to testData
3)rewriteRun task has been executed

* PR corrections

1)Change Test/comment place
  • Loading branch information
KonstantinosChanioglou authored Mar 19, 2024
1 parent 49eb6b2 commit 9babea4
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
9 changes: 2 additions & 7 deletions src/main/java/org/jabref/model/entry/identifier/DOI.java
Original file line number Diff line number Diff line change
Expand Up @@ -124,13 +124,8 @@ public DOI(String doi) {

// HTTP URL decoding
if (doi.matches(HTTP_EXP) || doi.matches(SHORT_DOI_HTTP_EXP)) {
try {
// decodes path segment
URI url = new URI(trimmedDoi);
trimmedDoi = url.getScheme() + "://" + url.getHost() + url.getPath();
} catch (URISyntaxException e) {
throw new IllegalArgumentException(doi + " is not a valid HTTP DOI/Short DOI.");
}
// decodes path segment
trimmedDoi = URLDecoder.decode(trimmedDoi, StandardCharsets.UTF_8);
}

// Extract DOI/Short DOI
Expand Down
10 changes: 10 additions & 0 deletions src/test/java/org/jabref/model/entry/identifier/DOITest.java
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,11 @@ private static Stream<Arguments> testData() {
Arguments.of("10.1006/rwei.1999 .0001", new DOI("http://doi.org/10.1006/rwei.1999%20.0001").getDOI()),
// ? -> (%3F)
Arguments.of("10.1006/rwei.1999?.0001", new DOI("http://doi.org/10.1006/rwei.1999%3F.0001").getDOI()),
// <,> -> (%3C, %3E)
Arguments.of("10.1175/1520-0493(2002)130<1913:EDAWPO>2.0.CO;2", new DOI("https://doi.org/10.1175/1520-0493(2002)130%3C1913:EDAWPO%3E2.0.CO;2").getDOI()),

// acceptDoiWithSpecialCharacters
Arguments.of("10.1175/1520-0493(2002)130<1913:EDAWPO>2.0.CO;2", new DOI("https://doi.org/10.1175/1520-0493(2002)130<1913:EDAWPO>2.0.CO;2").getDOI()),

// findDoiInsideArbitraryText
Arguments.of("10.1006/jmbi.1998.2354",
Expand Down Expand Up @@ -306,4 +311,9 @@ public void rejectMissingDivider() {
public void rejectMissingDividerInShortDoi() {
assertThrows(IllegalArgumentException.class, () -> new DOI("10gf4gqc end"));
}

@Test
public void rejectNullDoiParameter() {
assertThrows(NullPointerException.class, () -> new DOI(null));
}
}

0 comments on commit 9babea4

Please sign in to comment.