Don't strip punctuation before numbers

Fixes #2496
This commit is contained in:
Abe Jellinek 2022-03-30 11:30:24 -07:00
parent f2209974b2
commit 745069c070
2 changed files with 15 additions and 5 deletions

View file

@ -1983,11 +1983,9 @@ Zotero.Items = function() {
'</span>',
// Any punctuation at the beginning of the string
'^\\p{P}+',
// Initial, opening, closing, final, other punctuation:
// pretty much anything that isn't a connector/dash.
// Positively matching each of these classes compiles to a cleaner
// native RegExp than XRegExp('[^\\P{P}\\p{Pd}]')
'[\\p{Pi}\\p{Ps}\\p{Pe}\\p{Pf}\\p{Po}]'
// Initial, opening, closing, final, and "other" punctuation that isn't
// followed by a digit. Doesn't match connectors or dashes.
'[\\p{Pi}\\p{Ps}\\p{Pe}\\p{Pf}\\p{Po}](?!\\d)'
].map(re => Zotero.Utilities.XRegExp(re, 'g'));

View file

@ -1163,5 +1163,17 @@ describe("Zotero.Items", function () {
assert.equal(Zotero.Items.getSortTitle(input), expected);
}
});
it("should not strip any punctuation before a digit", function () {
let tests = [
['1.5', '1.5'],
['abc .5', 'abc .5'],
['abc 5.', 'abc 5']
];
for (let [input, expected] of tests) {
assert.equal(Zotero.Items.getSortTitle(input), expected);
}
});
});
});