Don't sanitize input from child web translators before passing it to parent translators
This commit is contained in:
parent
c549166e25
commit
70440ee8f9
1 changed files with 64 additions and 61 deletions
|
@ -522,73 +522,76 @@ Zotero.Translate.Sandbox = {
|
||||||
* @param {SandboxItem} An item created using the Zotero.Item class from the sandbox
|
* @param {SandboxItem} An item created using the Zotero.Item class from the sandbox
|
||||||
*/
|
*/
|
||||||
"_itemDone":function(translate, item) {
|
"_itemDone":function(translate, item) {
|
||||||
if(!item.itemType) {
|
// Only apply checks if there is no parent translator
|
||||||
item.itemType = "webpage";
|
if(!translate._parentTranslator) {
|
||||||
translate._debug("WARNING: No item type specified");
|
if(!item.itemType) {
|
||||||
}
|
item.itemType = "webpage";
|
||||||
|
translate._debug("WARNING: No item type specified");
|
||||||
if(item.type == "attachment" || item.type == "note") {
|
|
||||||
Zotero.debug("Translate: Discarding standalone "+item.type+" in non-import translator", 2);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// store library catalog if this item was captured from a website, and
|
|
||||||
// libraryCatalog is truly undefined (not false or "")
|
|
||||||
if(item.repository !== undefined) {
|
|
||||||
Zotero.debug("Translate: 'repository' field is now 'libraryCatalog'; please fix your code", 2);
|
|
||||||
item.libraryCatalog = item.repository;
|
|
||||||
delete item.repository;
|
|
||||||
}
|
|
||||||
|
|
||||||
// automatically set library catalog
|
|
||||||
if(item.libraryCatalog === undefined) {
|
|
||||||
item.libraryCatalog = translate.translator[0].label;
|
|
||||||
}
|
|
||||||
|
|
||||||
// automatically set access date if URL is set
|
|
||||||
if(item.url && typeof item.accessDate == 'undefined') {
|
|
||||||
item.accessDate = "CURRENT_TIMESTAMP";
|
|
||||||
}
|
|
||||||
|
|
||||||
if(!item.title) {
|
|
||||||
translate.complete(false, new Error("No title specified for item"));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// create short title
|
|
||||||
if(item.shortTitle === undefined && Zotero.Utilities.fieldIsValidForType("shortTitle", item.itemType)) {
|
|
||||||
// only set if changes have been made
|
|
||||||
var setShortTitle = false;
|
|
||||||
var title = item.title;
|
|
||||||
|
|
||||||
// shorten to before first colon
|
|
||||||
var index = title.indexOf(":");
|
|
||||||
if(index !== -1) {
|
|
||||||
title = title.substr(0, index);
|
|
||||||
setShortTitle = true;
|
|
||||||
}
|
}
|
||||||
// shorten to after first question mark
|
|
||||||
index = title.indexOf("?");
|
if(item.type == "attachment" || item.type == "note") {
|
||||||
if(index !== -1) {
|
Zotero.debug("Translate: Discarding standalone "+item.type+" in non-import translator", 2);
|
||||||
index++;
|
return;
|
||||||
if(index != title.length) {
|
}
|
||||||
|
|
||||||
|
// store library catalog if this item was captured from a website, and
|
||||||
|
// libraryCatalog is truly undefined (not false or "")
|
||||||
|
if(item.repository !== undefined) {
|
||||||
|
Zotero.debug("Translate: 'repository' field is now 'libraryCatalog'; please fix your code", 2);
|
||||||
|
item.libraryCatalog = item.repository;
|
||||||
|
delete item.repository;
|
||||||
|
}
|
||||||
|
|
||||||
|
// automatically set library catalog
|
||||||
|
if(item.libraryCatalog === undefined) {
|
||||||
|
item.libraryCatalog = translate.translator[0].label;
|
||||||
|
}
|
||||||
|
|
||||||
|
// automatically set access date if URL is set
|
||||||
|
if(item.url && typeof item.accessDate == 'undefined') {
|
||||||
|
item.accessDate = "CURRENT_TIMESTAMP";
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!item.title) {
|
||||||
|
translate.complete(false, new Error("No title specified for item"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// create short title
|
||||||
|
if(item.shortTitle === undefined && Zotero.Utilities.fieldIsValidForType("shortTitle", item.itemType)) {
|
||||||
|
// only set if changes have been made
|
||||||
|
var setShortTitle = false;
|
||||||
|
var title = item.title;
|
||||||
|
|
||||||
|
// shorten to before first colon
|
||||||
|
var index = title.indexOf(":");
|
||||||
|
if(index !== -1) {
|
||||||
title = title.substr(0, index);
|
title = title.substr(0, index);
|
||||||
setShortTitle = true;
|
setShortTitle = true;
|
||||||
}
|
}
|
||||||
|
// shorten to after first question mark
|
||||||
|
index = title.indexOf("?");
|
||||||
|
if(index !== -1) {
|
||||||
|
index++;
|
||||||
|
if(index != title.length) {
|
||||||
|
title = title.substr(0, index);
|
||||||
|
setShortTitle = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(setShortTitle) item.shortTitle = title;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(setShortTitle) item.shortTitle = title;
|
// refuse to save very long tags
|
||||||
}
|
if(item.tags) {
|
||||||
|
for(var i=0; i<item.tags.length; i++) {
|
||||||
// refuse to save very long tags
|
var tag = item.tags[i];
|
||||||
if(item.tags) {
|
tagString = typeof tag === "string" ? tag :
|
||||||
for(var i=0; i<item.tags.length; i++) {
|
typeof tag === "object" ? (tag.tag || tag.name) : null;
|
||||||
var tag = item.tags[i];
|
if(tagString && tagString.length > 255) {
|
||||||
tagString = typeof tag === "string" ? tag :
|
translate._debug("WARNING: Skipping unsynchable tag "+JSON.stringify(tagString));
|
||||||
typeof tag === "object" ? (tag.tag || tag.name) : null;
|
item.tags.splice(i--, 1);
|
||||||
if(tagString && tagString.length > 255) {
|
}
|
||||||
translate._debug("WARNING: Skipping unsynchable tag "+JSON.stringify(tagString));
|
|
||||||
item.tags.splice(i--, 1);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue