Strip bidi control characters in filenames and elsewhere (#3208)

Passing unformatted = true to Item#getField() now returns a bidi control
character-less result, and we use that in Reader#updateTitle() and
getFileBaseNameFromItem() to prevent bidi control characters from showing up in
filenames and window titles (the former everywhere, the latter on Windows only).

We also strip bidi control characters in getValidFileName() to be extra safe.
This commit is contained in:
Abe Jellinek 2023-07-22 03:30:28 -04:00 committed by GitHub
commit 676f820f87
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 92 additions and 19 deletions

View file

@ -35,6 +35,56 @@ describe("Zotero.Item", function () {
]);
assert.equal(item.getField('firstCreator'), "B");
});
it("should return a multi-author firstCreator for an unsaved item", async function () {
var item = createUnsavedDataObject('item');
item.setCreators([
{
firstName: "A",
lastName: "B",
creatorType: "author"
},
{
firstName: "C",
lastName: "D",
creatorType: "author"
}
]);
assert.equal(
item.getField('firstCreator'),
Zotero.getString('general.andJoiner', ['\u2068B\u2069', '\u2068D\u2069'])
);
});
it("should strip bidi isolates from firstCreator when unformatted = true", async function () {
var item = createUnsavedDataObject('item');
item.setCreators([
{
firstName: "A",
lastName: "B",
creatorType: "author"
},
{
firstName: "C",
lastName: "D",
creatorType: "author"
}
]);
// Test unsaved - uses getFirstCreatorFromData()'s omitBidiIsolates option
assert.equal(
item.getField('firstCreator', /* unformatted */ true),
Zotero.getString('general.andJoiner', ['B', 'D'])
);
await item.saveTx();
// Test saved - implemented in getField()
assert.equal(
item.getField('firstCreator', /* unformatted */ true),
Zotero.getString('general.andJoiner', ['B', 'D'])
);
});
});
describe("#setField", function () {