mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-12-12 00:50:40 +00:00
Bug 223549 GenerateValidFilename should use validateFileName p=ian@arlen.demon.co.uk r=me sr=bienvenu
This commit is contained in:
parent
c8a9a80ed2
commit
732bccfc0d
@ -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)
|
||||
|
@ -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, "_");
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user