зеркало из https://github.com/mozilla/gecko-dev.git
Bug 223549 GenerateValidFilename should use validateFileName p=ian@arlen.demon.co.uk r=me sr=bienvenu
This commit is contained in:
Родитель
c8a9a80ed2
Коммит
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, "_");
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче