Bug 223549 GenerateValidFilename should use validateFileName p=ian@arlen.demon.co.uk r=me sr=bienvenu

This commit is contained in:
neil%parkwaycc.co.uk 2003-10-30 10:12:32 +00:00
Родитель c8a9a80ed2
Коммит 732bccfc0d
2 изменённых файлов: 21 добавлений и 22 удалений

Просмотреть файл

@ -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, "_");
}