diff --git a/xpfe/communicator/resources/content/contentAreaUtils.js b/xpfe/communicator/resources/content/contentAreaUtils.js index bc70205186e7..e7800f158ca3 100644 --- a/xpfe/communicator/resources/content/contentAreaUtils.js +++ b/xpfe/communicator/resources/content/contentAreaUtils.js @@ -788,9 +788,9 @@ function getDefaultFileName(aDefaultFileName, aNameFromHeaders, aDocumentURI, aD } if (aDocument) { - var docTitle = validateFileName(aDocument.title).replace(/^\s+|\s+$/g, ""); + var docTitle = GenerateValidFilename(aDocument.title, ""); - if (docTitle != "") { + if (docTitle) { // 3) Use the document title return docTitle; } @@ -823,22 +823,6 @@ function getDefaultFileName(aDefaultFileName, aNameFromHeaders, aDocumentURI, aD return "index"; } -function validateFileName(aFileName) -{ - var re = /[\/]+/g; - if (navigator.appVersion.indexOf("Windows") != -1) { - re = /[\\\/\|]+/g; - aFileName = aFileName.replace(/[\"]+/g, "'"); - aFileName = aFileName.replace(/[\*\:\?]+/g, " "); - aFileName = aFileName.replace(/[\<]+/g, "("); - aFileName = aFileName.replace(/[\>]+/g, ")"); - } - else if (navigator.appVersion.indexOf("Macintosh") != -1) - re = /[\:\/]+/g; - - return aFileName.replace(re, "_"); -} - function getNormalizedLeafName(aFile, aDefaultExtension) { if (!aDefaultExtension) diff --git a/xpfe/communicator/resources/content/utilityOverlay.js b/xpfe/communicator/resources/content/utilityOverlay.js index ec003fa43097..236c5f88e71b 100644 --- a/xpfe/communicator/resources/content/utilityOverlay.js +++ b/xpfe/communicator/resources/content/utilityOverlay.js @@ -413,12 +413,27 @@ function GenerateValidFilename(filename, extension) { if (filename) // we have a title; let's see if it's usable { - // clean up the filename to make it usable - filename = filename.replace(/\"/g, ""); // Strip out quote character: " - filename = filename.replace(/(^\s+)|(\s+$)/g, ''); // trim whitespace from beginning and end - filename = filename.replace(/[ \.\\@\/:]/g, "_"); //Replace "bad" filename characters with "_" + // clean up the filename to make it usable and + // then trim whitespace from beginning and end + filename = validateFileName(filename).replace(/^\s+|\s+$/g, ""); if (filename.length > 0) return filename + extension; } return null; } + +function validateFileName(aFileName) +{ + var re = /[\/]+/g; + if (navigator.appVersion.indexOf("Windows") != -1) { + re = /[\\\/\|]+/g; + aFileName = aFileName.replace(/[\"]+/g, "'"); + aFileName = aFileName.replace(/[\*\:\?]+/g, " "); + aFileName = aFileName.replace(/[\<]+/g, "("); + aFileName = aFileName.replace(/[\>]+/g, ")"); + } + else if (navigator.appVersion.indexOf("Macintosh") != -1) + re = /[\:\/]+/g; + + return aFileName.replace(re, "_"); +}