sanitize-filename
Advanced tools
Comparing version 1.5.3 to 1.6.0
@@ -37,2 +37,3 @@ /*jshint node:true*/ | ||
var windowsReservedRe = /^(con|prn|aux|nul|com[0-9]|lpt[0-9])(\..*)?$/i; | ||
var windowsTrailingRe = /[\. ]+$/; | ||
@@ -44,3 +45,4 @@ function sanitize(input, replacement) { | ||
.replace(reservedRe, replacement) | ||
.replace(windowsReservedRe, replacement); | ||
.replace(windowsReservedRe, replacement) | ||
.replace(windowsTrailingRe, replacement); | ||
return truncate(sanitized, 255); | ||
@@ -47,0 +49,0 @@ } |
{ | ||
"name": "sanitize-filename", | ||
"version": "1.5.3", | ||
"version": "1.6.0", | ||
"description": "Sanitize a string for use as a filename", | ||
@@ -26,3 +26,3 @@ "main": "index.js", | ||
"devDependencies": { | ||
"browserify": "^12.0.1", | ||
"browserify": "^13.0.0", | ||
"concat-stream": "^1.5.1", | ||
@@ -29,0 +29,0 @@ "mktemp": "^0.4.0", |
@@ -31,8 +31,10 @@ # sanitize-filename [![build status](https://secure.travis-ci.org/parshap/node-sanitize-filename.svg?branch=master)](http://travis-ci.org/parshap/node-sanitize-filename) | ||
* [Control characters][] (`0x00-0x1f` and `0x80-0x9f`) | ||
* [Reserved characters][] (`/` `?` `<` `>` `\` `:` `*` `|` `"`) | ||
* [Control characters][] (`0x00`–`0x1f` and `0x80`–`0x9f`) | ||
* [Reserved characters][] (`/`, `?`, `<`, `>`, `\`, `:`, `*`, `|`, and | ||
`"`) | ||
* Unix reserved filenames (`.` and `..`) | ||
* Windows reserved filenames (`CON` `PRN` `AUX` `NUL` `COM1` | ||
`COM2` `COM3` `COM4` `COM5` `COM6` `COM7` `COM8` `COM9` | ||
`LPT1` `LPT2` `LPT3` `LPT4` `LPT5` `LPT6` `LPT7` `LPT8` and | ||
* Trailing periods and spaces ([for Windows][windows trailing]) | ||
* Windows reserved filenames (`CON`, `PRN`, `AUX`, `NUL`, `COM1`, | ||
`COM2`, `COM3`, `COM4`, `COM5`, `COM6`, `COM7`, `COM8`, `COM9`, | ||
`LPT1`, `LPT2`, `LPT3`, `LPT4`, `LPT5`, `LPT6`, `LPT7`, `LPT8`, and | ||
`LPT9`) | ||
@@ -42,2 +44,3 @@ | ||
[reserved characters]: https://kb.acronis.com/content/39790 | ||
[windows trailing]: https://msdn.microsoft.com/en-us/library/aa365247(v=vs.85).aspx#Naming_Conventions | ||
@@ -44,0 +47,0 @@ The resulting string is truncated to [255 bytes in length][255]. The |
10
test.js
@@ -63,2 +63,10 @@ "use strict"; | ||
// https://msdn.microsoft.com/en-us/library/aa365247(v=vs.85).aspx | ||
test("restricted suffixes", function(t) { | ||
["mr.", "mr..", "mr ", "mr "].forEach(function(name) { | ||
t.equal(sanitize(name), "mr"); | ||
}); | ||
t.end(); | ||
}); | ||
test("relative paths", function(t) { | ||
@@ -143,3 +151,3 @@ [".", "..", "./", "../", "/..", "/../", "*.|."].forEach(function(name) { | ||
// Should not contain any directories or relative paths | ||
t.equal(path.dirname(path.resolve("/abs/path", sanitized)), "/abs/path"); | ||
t.equal(path.dirname(path.resolve("/abs/path", sanitized)), path.resolve("/abs/path")); | ||
@@ -146,0 +154,0 @@ // Should be max 255 bytes |
131136
1245
101