зеркало из 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) {
|
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
|
// 3) Use the document title
|
||||||
return docTitle;
|
return docTitle;
|
||||||
}
|
}
|
||||||
|
@ -823,22 +823,6 @@ function getDefaultFileName(aDefaultFileName, aNameFromHeaders, aDocumentURI, aD
|
||||||
return "index";
|
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)
|
function getNormalizedLeafName(aFile, aDefaultExtension)
|
||||||
{
|
{
|
||||||
if (!aDefaultExtension)
|
if (!aDefaultExtension)
|
||||||
|
|
|
@ -413,12 +413,27 @@ function GenerateValidFilename(filename, extension)
|
||||||
{
|
{
|
||||||
if (filename) // we have a title; let's see if it's usable
|
if (filename) // we have a title; let's see if it's usable
|
||||||
{
|
{
|
||||||
// clean up the filename to make it usable
|
// clean up the filename to make it usable and
|
||||||
filename = filename.replace(/\"/g, ""); // Strip out quote character: "
|
// then trim whitespace from beginning and end
|
||||||
filename = filename.replace(/(^\s+)|(\s+$)/g, ''); // trim whitespace from beginning and end
|
filename = validateFileName(filename).replace(/^\s+|\s+$/g, "");
|
||||||
filename = filename.replace(/[ \.\\@\/:]/g, "_"); //Replace "bad" filename characters with "_"
|
|
||||||
if (filename.length > 0)
|
if (filename.length > 0)
|
||||||
return filename + extension;
|
return filename + extension;
|
||||||
}
|
}
|
||||||
return null;
|
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, "_");
|
||||||
|
}
|
||||||
|
|
Загрузка…
Ссылка в новой задаче