|
|
@ -14,13 +14,27 @@ function sanitizeUrl(unsafe) { |
|
|
|
.replace(/;/g, "%3B");
|
|
|
|
.replace(/;/g, "%3B");
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** Remove the most risky characters from a filename string */ |
|
|
|
/** |
|
|
|
|
|
|
|
* Remove the most risky characters from a filename string
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* Firefox doesn't allow these: |"*?:<> |
|
|
|
|
|
|
|
*/ |
|
|
|
function cleanFilename(unsafe) { |
|
|
|
function cleanFilename(unsafe) { |
|
|
|
return unsafe |
|
|
|
return unsafe |
|
|
|
.replace(/::/g, " - ") |
|
|
|
.replace(/::/g, " - ") // common delimiter (e.g. My Cool Article :: Website.com)
|
|
|
|
.replace(/[/\\?*|"'<>:]+/g, " ") |
|
|
|
.replace(/[?*]+/g, " ") // this is just noise, drop it
|
|
|
|
.replace(/\s+/g, " ") |
|
|
|
.replace(/[\<\[]/g, "(") |
|
|
|
.replace(/[\._-]$/g, "") |
|
|
|
.replace(/[\>\]]/g, ")") |
|
|
|
|
|
|
|
.replace(/ :/g, " -") |
|
|
|
|
|
|
|
.replace(/: /g, " ") |
|
|
|
|
|
|
|
.replace(/:/g, "_") |
|
|
|
|
|
|
|
.replace(/"/g, "'") // firefox hates double quote
|
|
|
|
|
|
|
|
.replace(/[/\\|]/g, "-") // porobable delimiters that should be kept in some form
|
|
|
|
|
|
|
|
.replace(/-+/g, "-") // collapse multiple hyphen (may result from substitutions)
|
|
|
|
|
|
|
|
.replace(/[\+=]/g, "_") // other suspicious stuff
|
|
|
|
|
|
|
|
.replace(/\s+/g, " ") // collapse multiple whitespace
|
|
|
|
|
|
|
|
.replace(/[\._,-]+$/g, "") // the filename should not end on special chars
|
|
|
|
|
|
|
|
.replace(/^[\._,-]+/g, "") // nor start
|
|
|
|
.trim(); |
|
|
|
.trim(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|