Skip to content

Commit e53c390

Browse files
authored
Fix DOI parsing error (JabRef#10405)
* Fix DOI parsing error Reported by Thilo * fix import
1 parent c66f863 commit e53c390

File tree

4 files changed

+14
-4
lines changed

4 files changed

+14
-4
lines changed

src/main/java/org/jabref/gui/fieldeditors/contextmenu/EditorMenus.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@
1010
import javafx.scene.control.TextInputControl;
1111

1212
import org.jabref.gui.DialogService;
13-
import org.jabref.gui.Globals;
1413
import org.jabref.gui.actions.ActionFactory;
1514
import org.jabref.gui.actions.StandardActions;
1615
import org.jabref.gui.edit.CopyDoiUrlAction;
1716
import org.jabref.logic.formatter.bibtexfields.CleanupUrlFormatter;
1817
import org.jabref.logic.formatter.bibtexfields.NormalizeNamesFormatter;
1918
import org.jabref.logic.l10n.Localization;
2019
import org.jabref.model.strings.StringUtil;
20+
import org.jabref.preferences.PreferencesService;
2121

2222
import com.tobiasdiez.easybind.EasyBind;
2323

@@ -53,9 +53,9 @@ public static Supplier<List<MenuItem>> getNameMenu(final TextInputControl textIn
5353
* @param textArea text-area that this menu will be connected to
5454
* @return menu containing items of the default menu and an item for copying a DOI/DOI URL
5555
*/
56-
public static Supplier<List<MenuItem>> getDOIMenu(TextArea textArea, DialogService dialogService) {
56+
public static Supplier<List<MenuItem>> getDOIMenu(TextArea textArea, DialogService dialogService, PreferencesService preferencesService) {
5757
return () -> {
58-
ActionFactory factory = new ActionFactory(Globals.getKeyPrefs());
58+
ActionFactory factory = new ActionFactory(preferencesService.getKeyBindingRepository());
5959
MenuItem copyDoiMenuItem = factory.createMenuItem(StandardActions.COPY_DOI, new CopyDoiUrlAction(textArea, StandardActions.COPY_DOI, dialogService));
6060
MenuItem copyDoiUrlMenuItem = factory.createMenuItem(StandardActions.COPY_DOI_URL, new CopyDoiUrlAction(textArea, StandardActions.COPY_DOI_URL, dialogService));
6161
List<MenuItem> menuItems = new ArrayList<>();

src/main/java/org/jabref/gui/fieldeditors/identifier/IdentifierEditor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public IdentifierEditor(Field field,
7575
new Tooltip(Localization.lang("Look up %0", field.getDisplayName())));
7676

7777
if (field.equals(StandardField.DOI)) {
78-
textArea.initContextMenu(EditorMenus.getDOIMenu(textArea, dialogService));
78+
textArea.initContextMenu(EditorMenus.getDOIMenu(textArea, dialogService, preferencesService));
7979
} else {
8080
textArea.initContextMenu(new DefaultMenu(textArea));
8181
}

src/main/java/org/jabref/model/entry/identifier/DOI.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,9 @@ public static Optional<DOI> parse(String doi) {
171171
cleanedDOI = cleanedDOI.replaceAll(CHARS_TO_REMOVE, "");
172172

173173
if (cleanedDOI.startsWith("_") && cleanedDOI.endsWith("_")) {
174+
if (cleanedDOI.length() == 1) {
175+
return Optional.empty();
176+
}
174177
cleanedDOI = cleanedDOI.substring(1, cleanedDOI.length() - 1);
175178
}
176179

src/test/java/org/jabref/model/entry/identifier/DOITest.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,13 @@ public void rejectInvalidDirectoryIndicatorInShortDoi() {
266266
assertThrows(IllegalArgumentException.class, () -> new DOI("20/abcd"));
267267
}
268268

269+
@Test
270+
public void emptyOrUndescoreOnlyReturnsEmpty() {
271+
assertEquals(Optional.empty(), DOI.parse("_"));
272+
assertEquals(Optional.empty(), DOI.parse("\t_"));
273+
assertEquals(Optional.empty(), DOI.parse("___"));
274+
}
275+
269276
@Test
270277
public void rejectInvalidDoiUri() {
271278
assertThrows(IllegalArgumentException.class, () -> new DOI("https://thisisnouri"));

0 commit comments

Comments
 (0)