Trim spaces from values in getFileBaseNameFromItem (#3711)
This commit is contained in:
parent
61d3c5c85c
commit
1b751d675b
2 changed files with 25 additions and 1 deletions
|
@ -2187,6 +2187,9 @@ Zotero.Attachments = new function () {
|
|||
if (truncate) {
|
||||
value = value.substr(0, truncate);
|
||||
}
|
||||
|
||||
value = value.trim();
|
||||
|
||||
if (prefix) {
|
||||
value = prefix + value;
|
||||
}
|
||||
|
|
|
@ -1290,7 +1290,7 @@ describe("Zotero.Attachments", function() {
|
|||
});
|
||||
|
||||
describe("#getFileBaseNameFromItem()", function () {
|
||||
var item, itemManyAuthors, itemPatent, itemIncomplete, itemBookSection;
|
||||
var item, itemManyAuthors, itemPatent, itemIncomplete, itemBookSection, itemSpaces;
|
||||
|
||||
before(() => {
|
||||
item = createUnsavedDataObject('item', { title: 'Lorem Ipsum', itemType: 'journalArticle' });
|
||||
|
@ -1331,6 +1331,7 @@ describe("Zotero.Attachments", function() {
|
|||
itemIncomplete = createUnsavedDataObject('item', { title: 'Incomplete', itemType: 'preprint' });
|
||||
itemBookSection = createUnsavedDataObject('item', { title: 'Book Section', itemType: 'bookSection' });
|
||||
itemBookSection.setField('bookTitle', 'Book Title');
|
||||
itemSpaces = createUnsavedDataObject('item', { title: ' Spaces! ', itemType: 'book' });
|
||||
});
|
||||
|
||||
|
||||
|
@ -1363,6 +1364,26 @@ describe("Zotero.Attachments", function() {
|
|||
);
|
||||
});
|
||||
|
||||
it('should trim whitespaces from a value', function () {
|
||||
assert.equal(
|
||||
Zotero.Attachments.getFileBaseNameFromItem(itemSpaces, '{{ title }}'),
|
||||
'Spaces!'
|
||||
);
|
||||
assert.equal(
|
||||
Zotero.Attachments.getFileBaseNameFromItem(item, '{{title truncate="6"}}'),
|
||||
'Lorem'
|
||||
);
|
||||
assert.equal(
|
||||
Zotero.Attachments.getFileBaseNameFromItem(item, '{{firstCreator truncate="7"}}'),
|
||||
'Barius'
|
||||
);
|
||||
// but preserve if it's configured as a prefix or suffix
|
||||
assert.equal(
|
||||
Zotero.Attachments.getFileBaseNameFromItem(item, '{{title prefix=" " suffix=" "}}'),
|
||||
' Lorem Ipsum '
|
||||
);
|
||||
});
|
||||
|
||||
it('should offer a range of options for composing creators', function () {
|
||||
assert.equal(
|
||||
Zotero.Attachments.getFileBaseNameFromItem(item, '{{ authors max="1" }}'),
|
||||
|
|
Loading…
Reference in a new issue