commit 37b65d70f8a93ba34cd4a9a36b7d606943022884
parent 695cb4710669a6580a74b28989f06932c9162793
Author: SASAKI Suguru <sss.sonik@gmail.com>
Date: Wed, 4 Jul 2012 19:37:49 +0900
Use hex-encoded MD5 of fileBaseName if it is in malformed URI sequence.
If the final component of URI can't be decoded with
decodeURIComponent(), Zotero fails to capture a web page,
because Zotero.Attachments._getFileNameFromURL() fails
with 'malformed URI sequence' error.
If we got 'malformed URI sequence' error,
try hex-encoded MD5 of URI's basename instead.
Signed-off-by: SASAKI Suguru <sss.sonik@gmail.com>
Diffstat:
1 file changed, 17 insertions(+), 1 deletion(-)
diff --git a/chrome/content/zotero/xpcom/attachments.js b/chrome/content/zotero/xpcom/attachments.js
@@ -1164,8 +1164,24 @@ Zotero.Attachments = new function(){
nsIURL.fileBaseName = nsIURL.fileBaseName + '.' + tld;
}
+ // Unencode fileBaseName
+ var decodedFileBaseName;
+ try {
+ decodedFileBaseName = decodeURIComponent(nsIURL.fileBaseName);
+ }
+ catch (e) {
+ if (e.name == 'URIError') {
+ // If we got a 'malformed URI sequence' while decoding,
+ // try MD5 (in hex string) of fileBaseName.
+ decodedFileBaseName = Zotero.Utilities.Internal.md5(nsIURL.fileBaseName, false);
+ }
+ else {
+ throw e;
+ }
+ }
+
// Pass unencoded name to getValidFileName() so that '%20' isn't stripped to '20'
- nsIURL.fileBaseName = Zotero.File.getValidFileName(decodeURIComponent(nsIURL.fileBaseName));
+ nsIURL.fileBaseName = Zotero.File.getValidFileName(decodedFileBaseName);
return decodeURIComponent(nsIURL.fileName);
}