From 9babea4f460e70d39c484089850cdea1edd87ca5 Mon Sep 17 00:00:00 2001 From: Konstantinos Chanioglou Date: Tue, 19 Mar 2024 20:19:16 +0100 Subject: [PATCH] Allow encoded HTTP URL to create new entry (#11036) * Fix for Issue #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 --- .../java/org/jabref/model/entry/identifier/DOI.java | 9 ++------- .../org/jabref/model/entry/identifier/DOITest.java | 10 ++++++++++ 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/src/main/java/org/jabref/model/entry/identifier/DOI.java b/src/main/java/org/jabref/model/entry/identifier/DOI.java index 2da8aa76509..1212b658606 100644 --- a/src/main/java/org/jabref/model/entry/identifier/DOI.java +++ b/src/main/java/org/jabref/model/entry/identifier/DOI.java @@ -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 diff --git a/src/test/java/org/jabref/model/entry/identifier/DOITest.java b/src/test/java/org/jabref/model/entry/identifier/DOITest.java index 628209d2a0a..685dfb7d712 100644 --- a/src/test/java/org/jabref/model/entry/identifier/DOITest.java +++ b/src/test/java/org/jabref/model/entry/identifier/DOITest.java @@ -186,6 +186,11 @@ private static Stream 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", @@ -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)); + } }