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;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var value;
|
||||||
switch (field) {
|
switch (field) {
|
||||||
|
case 'title':
|
||||||
|
value = item.getField('title', false, true);
|
||||||
|
break;
|
||||||
|
|
||||||
case 'year':
|
case 'year':
|
||||||
var value = item.getField('date', true, true);
|
value = item.getField('date', true, true);
|
||||||
if (value) {
|
if (value) {
|
||||||
value = Zotero.Date.multipartToSQL(value).substr(0, 4);
|
value = Zotero.Date.multipartToSQL(value).substr(0, 4);
|
||||||
if (value == '0000') {
|
if (value == '0000') {
|
||||||
|
@ -1899,7 +1904,7 @@ Zotero.Attachments = new function(){
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
var value = '' + item.getField(field, false, true);
|
value = '' + item.getField(field, false, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
var re = new RegExp("\{?([^%\{\}]*)" + rpl + "(\{[0-9]+\})?" + "([^%\{\}]*)\}?");
|
var re = new RegExp("\{?([^%\{\}]*)" + rpl + "(\{[0-9]+\})?" + "([^%\{\}]*)\}?");
|
||||||
|
@ -1924,6 +1929,7 @@ Zotero.Attachments = new function(){
|
||||||
formatString = rpl('year');
|
formatString = rpl('year');
|
||||||
formatString = rpl('title');
|
formatString = rpl('title');
|
||||||
|
|
||||||
|
formatString = Zotero.Utilities.cleanTags(formatString);
|
||||||
formatString = Zotero.File.getValidFileName(formatString);
|
formatString = Zotero.File.getValidFileName(formatString);
|
||||||
return 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 () {
|
describe("#getBaseDirectoryRelativePath()", function () {
|
||||||
it("should handle base directory at Windows drive root", function () {
|
it("should handle base directory at Windows drive root", function () {
|
||||||
Zotero.Prefs.set('baseAttachmentPath', "C:\\");
|
Zotero.Prefs.set('baseAttachmentPath', "C:\\");
|
||||||
|
|
Loading…
Reference in a new issue