Fixes #778, Overzealous PNAS (HighWire) blocking

This was due to a bug in WebPageDump/ScrapBook that would make invalid requests when various source attributes included relative paths to files in different directories. PNAS was blocking after 20 or so 404s for image files.
This commit is contained in:
Dan Stillman 2008-03-26 01:19:43 +00:00
parent be2a11793b
commit 95e71c41d8

View File

@ -343,8 +343,9 @@ var wpdDOMSaver = {
aDownload=aNode.complete;
} catch(ex) {}
}
var aFileName = this.download(aNode.src,aDownload);
if (aFileName) aNode.setAttribute("src", aFileName);
var aFileName = this.download(aNode.src,aDownload);
// Changed by Dan S. for Zotero -- see this.repairRelativeLinks()
if (aFileName) aNode.setAttribute("src", this.relativeLinkFix(aFileName));
} else {
return wpdCommon.removeNodeFromParent(aNode);
}
@ -352,7 +353,8 @@ var wpdDOMSaver = {
case "object" : // for embedding different data sources in the html page
if ( this.option["format"] ) {
var aFileName = this.download(aNode.data,true);
if (aFileName) aNode.setAttribute("data", aFileName);
// Changed by Dan S. for Zotero -- see this.repairRelativeLinks()
if (aFileName) aNode.setAttribute("data", this.relativeLinkFix(aFileName));
} else {
return wpdCommon.removeNodeFromParent(aNode);
}
@ -360,7 +362,8 @@ var wpdDOMSaver = {
case "body" :
if ( this.option["format"] ) {
var aFileName = this.download(aNode.background,true);
if (aFileName) aNode.setAttribute("background", aFileName);
// Changed by Dan S. for Zotero -- see this.repairRelativeLinks()
if (aFileName) aNode.setAttribute("background", this.relativeLinkFix(aFileName));
} else {
aNode.removeAttribute("background");
aNode.removeAttribute("bgcolor");
@ -373,7 +376,8 @@ var wpdDOMSaver = {
case "td" :
if ( this.option["format"] ) {
var aFileName = this.download(aNode.getAttribute("background"),true);
if (aFileName) aNode.setAttribute("background", aFileName);
// Changed by Dan S. for Zotero -- see this.repairRelativeLinks()
if (aFileName) aNode.setAttribute("background", this.relativeLinkFix(aFileName));
} else {
aNode.removeAttribute("background");
aNode.removeAttribute("bgcolor");
@ -383,7 +387,8 @@ var wpdDOMSaver = {
if ( aNode.type.toLowerCase() == "image" ) {
if ( this.option["format"] ) {
var aFileName = this.download(aNode.src,true);
if (aFileName) aNode.setAttribute("src", aFileName);
// Changed by Dan S. for Zotero -- see this.repairRelativeLinks()
if (aFileName) aNode.setAttribute("src", this.relativeLinkFix(aFileName));
} else {
aNode.setAttribute("type", "button");
aNode.removeAttribute("src");
@ -399,10 +404,12 @@ var wpdDOMSaver = {
return wpdCommon.removeNodeFromParent(aNode);
} else if ( (aNode.getAttribute("rel").toLowerCase() == "shortcut icon") || (aNode.getAttribute("rel").toLowerCase() == "icon") ) {
var aFileName = this.download(aNode.href,true);
if (aFileName) aNode.setAttribute("href", aFileName);
// Changed by Dan S. for Zotero -- see this.repairRelativeLinks()
if (aFileName) aNode.setAttribute("href", this.relativeLinkFix(aFileName));
} else if (aNode.getAttribute("rel").toLowerCase() == "fontdef") {
var aFileName = this.download(aNode.src,true);
if (aFileName) aNode.setAttribute("src", aFileName);
// Changed by Dan S. for Zotero -- see this.repairRelativeLinks()
if (aFileName) aNode.setAttribute("src", this.relativeLinkFix(aFileName));
} else {
aNode.setAttribute("href", aNode.href);
}
@ -419,7 +426,8 @@ var wpdDOMSaver = {
if ( this.option["script"] ) {
if ( aNode.hasAttribute("src") ) {
var aFileName = this.download(aNode.src,true);
if (aFileName) aNode.setAttribute("src", aFileName);
// Changed by Dan S. for Zotero -- see this.repairRelativeLinks()
if (aFileName) aNode.setAttribute("src", this.relativeLinkFix(aFileName));
}
} else {
if ( WPD_JAVASCRIPTSRCBUG && aNode.hasAttribute("src") ) {
@ -566,7 +574,23 @@ var wpdDOMSaver = {
}
return aHTMLText;
},
relativeLinkFix : function(aFileName)
{
return "about:blank?" + aFileName;
},
// Added by Dan S. for Zotero to restore relative links,
// which are prepended with "about:blank?" to fix a bug in Scrapbook/WPD
// that sending an invalid request to the server when the img src
// is a relative link to a file in a different directory
repairRelativeLinks : function(aHTMLText)
{
return aHTMLText.replace(/(src)="about:blank\?([^"]*)"/g, '$1="$2"');
},
// process the CSS text of one stylesheet element
processCSSText : function(aCSStext, aCSShref, inline)
{
@ -760,7 +784,11 @@ var wpdDOMSaver = {
HTMLText = HTMLText.replace(/\x00/g, " ");
// replace the & added by the innerHTML method
// because we have already generated all entities
if (WPD_ENTITYBUG) HTMLText = HTMLText.replace(/&/g,"&");
if (WPD_ENTITYBUG) HTMLText = HTMLText.replace(/&/g,"&");
// Added by Dan S. for Zotero
HTMLText = this.repairRelativeLinks(HTMLText);
return this.repairInlineCSS(HTMLText);
},