Strip HTML tags from titles when generating filenames
This commit is contained in:
parent
d7ee3fdee2
commit
b2e902746a
2 changed files with 16 additions and 2 deletions
|
@ -1887,9 +1887,14 @@ Zotero.Attachments = new function(){
|
|||
break;
|
||||
}
|
||||
|
||||
var value;
|
||||
switch (field) {
|
||||
case 'title':
|
||||
value = item.getField('title', false, true);
|
||||
break;
|
||||
|
||||
case 'year':
|
||||
var value = item.getField('date', true, true);
|
||||
value = item.getField('date', true, true);
|
||||
if (value) {
|
||||
value = Zotero.Date.multipartToSQL(value).substr(0, 4);
|
||||
if (value == '0000') {
|
||||
|
@ -1899,7 +1904,7 @@ Zotero.Attachments = new function(){
|
|||
break;
|
||||
|
||||
default:
|
||||
var value = '' + item.getField(field, false, true);
|
||||
value = '' + item.getField(field, false, true);
|
||||
}
|
||||
|
||||
var re = new RegExp("\{?([^%\{\}]*)" + rpl + "(\{[0-9]+\})?" + "([^%\{\}]*)\}?");
|
||||
|
@ -1924,6 +1929,7 @@ Zotero.Attachments = new function(){
|
|||
formatString = rpl('year');
|
||||
formatString = rpl('title');
|
||||
|
||||
formatString = Zotero.Utilities.cleanTags(formatString);
|
||||
formatString = Zotero.File.getValidFileName(formatString);
|
||||
return formatString;
|
||||
}
|
||||
|
|
|
@ -971,6 +971,14 @@ describe("Zotero.Attachments", function() {
|
|||
});
|
||||
});
|
||||
|
||||
describe("#getFileBaseNameFromItem()", function () {
|
||||
it("should strip HTML tags from title", async function () {
|
||||
var item = createUnsavedDataObject('item', { title: 'Foo <i>Bar</i> Foo<br><br/><br />Bar' });
|
||||
var str = Zotero.Attachments.getFileBaseNameFromItem(item);
|
||||
assert.equal(str, 'Foo Bar Foo Bar');
|
||||
});
|
||||
});
|
||||
|
||||
describe("#getBaseDirectoryRelativePath()", function () {
|
||||
it("should handle base directory at Windows drive root", function () {
|
||||
Zotero.Prefs.set('baseAttachmentPath', "C:\\");
|
||||
|
|
Loading…
Reference in a new issue