diff --git a/filenamify.js b/filenamify.js index 274c228..a548430 100644 --- a/filenamify.js +++ b/filenamify.js @@ -8,6 +8,7 @@ const MAX_FILENAME_LENGTH = 100; const reControlChars = /[\u0000-\u001f\u0080-\u009f]/g; // eslint-disable-line no-control-regex const reRelativePath = /^\.+/; +const reTrailingPeriods = /\.+$/; const filenamify = (string, options = {}) => { if (typeof string !== 'string') { @@ -23,6 +24,7 @@ const filenamify = (string, options = {}) => { string = string.replace(filenameReservedRegex(), replacement); string = string.replace(reControlChars, replacement); string = string.replace(reRelativePath, replacement); + string = string.replace(reTrailingPeriods, ''); if (replacement.length > 0) { string = trimRepeated(string, replacement); diff --git a/readme.md b/readme.md index 26dc83d..3b0d747 100644 --- a/readme.md +++ b/readme.md @@ -2,7 +2,7 @@ > Convert a string to a valid safe filename -On Unix-like systems `/` is reserved and [`<>:"/\|?*`](http://msdn.microsoft.com/en-us/library/aa365247%28VS.85%29#naming_conventions) on Windows. +On Unix-like systems, `/` is reserved. On Windows, [`<>:"/\|?*`](http://msdn.microsoft.com/en-us/library/aa365247%28VS.85%29#naming_conventions) along with trailing periods are reserved. ## Install diff --git a/test.js b/test.js index 131eec3..1dbba59 100644 --- a/test.js +++ b/test.js @@ -14,6 +14,9 @@ test('filnamify()', t => { t.is(filenamify('..'), '!'); t.is(filenamify('./'), '!'); t.is(filenamify('../'), '!'); + t.is(filenamify('foo.bar.'), 'foo.bar'); + t.is(filenamify('foo.bar..'), 'foo.bar'); + t.is(filenamify('foo.bar...'), 'foo.bar'); t.is(filenamify('con'), 'con!'); t.is(filenamify('foo/bar/nul'), 'foo!bar!nul'); t.is(filenamify('con', {replacement: '🐴🐴'}), 'con🐴🐴');