Skip to content

Commit 05ab831

Browse files
committed
[BibTeX] Fix cap protection for first word
Re https://forums.zotero.org/discussion/46690/exporting-error/ Can't believe I made that mistake
1 parent 45a1588 commit 05ab831

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

BibTeX.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
"inRepository": true,
1919
"translatorType": 3,
2020
"browserSupport": "gcsv",
21-
"lastUpdated": "2015-02-12 07:13:30"
21+
"lastUpdated": "2015-02-16 03:35:30"
2222
}
2323

2424
function detectImport() {
@@ -902,7 +902,7 @@ function writeField(field, value, isMacro) {
902902
value = value.replace(/[|\<\>\~\^\\\{\}]/g, mapEscape).replace(/([\#\$\%\&\_])/g, "\\$1");
903903

904904
if (caseProtectedFields.indexOf(field) != -1) {
905-
value = ZU.XRegExp.replace(value, protectCapsRE, "$1{$2}");
905+
value = ZU.XRegExp.replace(value, protectCapsRE, "$1{$2$3}"); // only $2 or $3 will have a value, not both
906906
}
907907
}
908908
if (Zotero.getOption("exportCharset") != "UTF-8") {
@@ -1109,15 +1109,15 @@ function doExport() {
11091109
if (Zotero.getHiddenPref && Zotero.getHiddenPref('BibTeX.export.dontProtectInitialCase')) {
11101110
// Case of words with uppercase characters in non-initial positions is
11111111
// preserved with braces.
1112-
// Two captures because of the other regexp below
1113-
protectCapsRE = new ZU.XRegExp("()\\b(\\p{Letter}+\\p{Uppercase_Letter}\\p{Letter}*)", 'g');
1112+
// Two extra captures because of the other regexp below
1113+
protectCapsRE = new ZU.XRegExp("()()\\b(\\p{Letter}+\\p{Uppercase_Letter}\\p{Letter}*)", 'g');
11141114
} else {
11151115
// Protect all upper case letters, even if the uppercase letter is only in
11161116
// initial position of the word.
11171117
// Don't protect first word if only first letter is capitalized
11181118
protectCapsRE = new ZU.XRegExp(
11191119
"(.)\\b(\\p{Letter}*\\p{Uppercase_Letter}\\p{Letter}*)" // Non-initial words with capital letter anywhere
1120-
+ "|^()(\\p{Letter}+\\p{Uppercase_Letter}\\p{Letter}*)" // Initial word with capital in non-initial position
1120+
+ "|^(\\p{Letter}+\\p{Uppercase_Letter}\\p{Letter}*)" // Initial word with capital in non-initial position
11211121
, 'g');
11221122
}
11231123

0 commit comments

Comments
 (0)