From f9e981df64d153010b85a5e1e46e1d15e71c6e04 Mon Sep 17 00:00:00 2001 From: Oliver Kopp Date: Sun, 3 Nov 2024 17:40:48 +0100 Subject: [PATCH] Allow - in citaton keys --- CHANGELOG.md | 1 + .../CitationKeyGenerator.java | 12 +++++----- .../CitationKeyGeneratorTest.java | 22 +++++++++++-------- .../bibtexfields/RegexFormatterTest.java | 6 +++++ 4 files changed, 26 insertions(+), 15 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 38e1c8b26c9..860cca1b828 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -73,6 +73,7 @@ Note that this project **does not** adhere to [Semantic Versioning](https://semv - When importing a file using "Find Unlinked Files", when one or more file directories are available, the file path will be relativized where possible [koppor#549](https://github.com/koppor/jabref/issues/549) - We added minimum window sizing for windows dedicated to creating new entries [#11944](https://github.com/JabRef/jabref/issues/11944) - We changed the name of the library-based file directory from 'General File Directory' to 'Library-specific File Directory' per issue. [#571](https://github.com/koppor/jabref/issues/571) +- We allow a dash (`-`) being part in a citation key. - The CitationKey column is now a default shown column for the entry table. [#10510](https://github.com/JabRef/jabref/issues/10510) ### Fixed diff --git a/src/main/java/org/jabref/logic/citationkeypattern/CitationKeyGenerator.java b/src/main/java/org/jabref/logic/citationkeypattern/CitationKeyGenerator.java index 9438194a2d2..8cf6fc58aeb 100644 --- a/src/main/java/org/jabref/logic/citationkeypattern/CitationKeyGenerator.java +++ b/src/main/java/org/jabref/logic/citationkeypattern/CitationKeyGenerator.java @@ -26,12 +26,12 @@ public class CitationKeyGenerator extends BracketedPattern { */ public static final String APPENDIX_CHARACTERS = "abcdefghijklmnopqrstuvwxyz"; - /** - * List of unwanted characters. These will be removed at the end. - * Note that + is a wanted character to indicate "et al." in authorsAlpha. - * Example: "ABC+". See {@link org.jabref.logic.citationkeypattern.BracketedPatternTest#authorsAlpha()} for examples. - */ - public static final String DEFAULT_UNWANTED_CHARACTERS = "-`ʹ:!;?^"; + /// List of unwanted characters. These will be removed at the end. + /// Note that `+` is a wanted character to indicate "et al." in authorsAlpha. + /// Example: `ABC+`. See {@link org.jabref.logic.citationkeypattern.BracketedPatternTest#authorsAlpha()} for examples. + /// + /// Source: authors() { + return Stream.of( + Arguments.of("Newton", AUTHOR_FIRSTNAME_INITIAL_LASTNAME_FULL_COUNT_1, "[authors]"), + Arguments.of("NewtonMaxwell", AUTHOR_FIRSTNAME_INITIAL_LASTNAME_FULL_COUNT_2, "[authors]"), + Arguments.of("NewtonMaxwellEinstein", AUTHOR_FIRSTNAME_INITIAL_LASTNAME_FULL_COUNT_3, "[authors]"), + Arguments.of("Newton-Maxwell-Einstein", AUTHOR_FIRSTNAME_INITIAL_LASTNAME_FULL_COUNT_3, "[authors:regex(\"(.)([A-Z])\",\"$1-$2\")]") + ); } static Stream authorsAlpha() { diff --git a/src/test/java/org/jabref/logic/formatter/bibtexfields/RegexFormatterTest.java b/src/test/java/org/jabref/logic/formatter/bibtexfields/RegexFormatterTest.java index dc478a9cb3d..b8d2b6aa4be 100644 --- a/src/test/java/org/jabref/logic/formatter/bibtexfields/RegexFormatterTest.java +++ b/src/test/java/org/jabref/logic/formatter/bibtexfields/RegexFormatterTest.java @@ -85,4 +85,10 @@ void extractFirstWord() { formatter = new RegexFormatter("(\"(\\w+).*\", \"$1\")"); assertEquals("First", formatter.format("First Second Third")); } + + @Test + void addDash() { + formatter = new RegexFormatter("(\"(.)([A-Z])\", \"$1-$2\")"); + assertEquals("First-Second-Third", formatter.format("FirstSecondThird")); + } }