Merge pull request #142 from sss/handle-malformed-uri-sequence-in-getFileNameFromURL
Use hex-encoded MD5 of fileBaseName if it is in malformed URI sequence.
This commit is contained in:
commit
325c78d1d2
1 changed files with 17 additions and 1 deletions
|
@ -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);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue