Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for some Unicode characters in citation keys #6938

Merged
merged 4 commits into from
Sep 26, 2020
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/main/java/org/jabref/model/strings/StringUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLConnection;
import java.text.Normalizer;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
Expand Down Expand Up @@ -587,7 +588,7 @@ public static String limitStringLength(String s, int maxLength) {
* accept. The basis for replacement is the HashMap UnicodeToReadableCharMap.
*/
public static String replaceSpecialCharacters(String s) {
String result = s;
String result = Normalizer.normalize(s, Normalizer.Form.NFC);
for (Map.Entry<String, String> chrAndReplace : UNICODE_CHAR_MAP.entrySet()) {
result = result.replace(chrAndReplace.getKey(), chrAndReplace.getValue());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1094,4 +1094,11 @@ void generateKeyCorrectKeyLengthWithAuthNofMthAndUnicode() {

assertEquals(4, generateKey(bibEntry, "[auth4_1]").length());
}

@Test
void generateKeyWithNonNormalizedUnicode() {
BibEntry bibEntry = new BibEntry().withField(StandardField.TITLE, "Modèle et outil pour soutenir la scénarisation pédagogique de MOOC connectivistes");

assertEquals("Modele", generateKey(bibEntry, "[veryshorttitle]"));
}
}
5 changes: 5 additions & 0 deletions src/test/java/org/jabref/model/strings/StringUtilTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,11 @@ void testReplaceSpecialCharacters() {
assertEquals("aaAeoeeee", StringUtil.replaceSpecialCharacters("åÄöéèë"));
}

@Test
void replaceSpecialCharactersWithNonNormalizedUnicode() {
assertEquals("Modele", StringUtil.replaceSpecialCharacters("Modèle"));
}

@Test
void testRepeatSpaces() {
assertEquals("", StringUtil.repeatSpaces(0));
Expand Down