Skip to content

Commit

Permalink
Fix DOI Url parsing (#11084)
Browse files Browse the repository at this point in the history
* Update changelog

* Fix regex pattern match, patch success

* Add test

* Fix test

* Fix test, as forbidden ';' was not terminating a doi case
  • Loading branch information
subhramit authored Mar 24, 2024
1 parent 8d08279 commit 4432dcf
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ Note that this project **does not** adhere to [Semantic Versioning](https://semv
- Fixed an issue on Windows where the browser extension reported failure to send an entry to JabRef even though it was sent properly. [JabRef-Browser-Extension#493](https://github.com/JabRef/JabRef-Browser-Extension/issues/493)
- Fixed an issue on Windows where TeXworks path was not resolved if it was installed with MiKTeX. [#10977](https://github.com/JabRef/jabref/issues/10977)
- We fixed an issue with where JabRef would throw an error when using MathSciNet search, as it was unable to parse the fetched JSON coreectly. [10996](https://github.com/JabRef/jabref/issues/10996)
- We fixed an issue where the "Import by ID" function would throw an error when a DOI that contains URL-encoded characters was entered. [#10648](https://github.com/JabRef/jabref/issues/10648)

### Removed

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/jabref/model/entry/identifier/DOI.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public class DOI implements Identifier {
+ "10" // directory indicator
+ "(?:\\.[0-9]+)+" // registrant codes
+ "[/:]" // divider
+ "(?:[^\\s,;]+[^,;(\\.\\s)])" // suffix alphanumeric without " "/","/";" and not ending on "."/","/";"
+ "(?:[^\\s,]+[^,;(\\.\\s)])" // suffix alphanumeric without " "/"," and not ending on "."/","/";"
+ ")"; // end group \1

// Regex (Short DOI)
Expand Down
8 changes: 7 additions & 1 deletion src/test/java/org/jabref/model/entry/identifier/DOITest.java
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ private static Stream<Arguments> testData() {
Arguments.of("10.1007/s10549-018-4743-9",
DOI.findInText("Breast Cancer Res Treat. 2018 July ; 170(1): 77–87. doi:10.1007/s10549-018-4743-9, ").get().getDOI()),
Arguments.of("10.1007/s10549-018-4743-9",
DOI.findInText("Breast Cancer Res Treat. 2018 July ; 170(1): 77–87. doi:10.1007/s10549-018-4743-9;something else").get().getDOI()),
DOI.findInText("Breast Cancer Res Treat. 2018 July ; 170(1): 77–87. doi:10.1007/s10549-018-4743-9; something else").get().getDOI()),
Arguments.of("10.1007/s10549-018-4743-9.1234",
DOI.findInText("bla doi:10.1007/s10549-018-4743-9.1234 with . in doi").get().getDOI()),

Expand Down Expand Up @@ -316,4 +316,10 @@ public void rejectMissingDividerInShortDoi() {
public void rejectNullDoiParameter() {
assertThrows(NullPointerException.class, () -> new DOI(null));
}

@Test
public void findDoiWithSpecialCharactersInText() {
assertEquals(Optional.of(new DOI("10.1175/1520-0493(2002)130%3C1913:EDAWPO%3E2.0.CO;2")),
DOI.findInText("https://doi.org/10.1175/1520-0493(2002)130%3C1913:EDAWPO%3E2.0.CO;2"));
}
}

0 comments on commit 4432dcf

Please # to comment.