From 3d308473e6f877d0438fd7b2fb15620e61cc1a15 Mon Sep 17 00:00:00 2001 From: Miraclx Date: Mon, 26 Apr 2021 03:06:53 +0100 Subject: [PATCH 1/4] replace trailing periods for consistency on Windows --- filenamify.js | 2 ++ 1 file changed, 2 insertions(+) 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); From 5bfb3bae21ed6f3c124da52b3ff6bc5c1e62485c Mon Sep 17 00:00:00 2001 From: Miraclx Date: Mon, 26 Apr 2021 03:14:01 +0100 Subject: [PATCH 2/4] update readme --- readme.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/readme.md b/readme.md index 26dc83d..d53c6d5 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 From 0c662a25da6a42fd17235d23fdd82a69c6c5e380 Mon Sep 17 00:00:00 2001 From: Sindre Sorhus Date: Mon, 26 Apr 2021 21:14:19 +0700 Subject: [PATCH 3/4] Update readme.md --- readme.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/readme.md b/readme.md index d53c6d5..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. On Windows, [`<>:"/\|?*`](http://msdn.microsoft.com/en-us/library/aa365247%28VS.85%29#naming_conventions) along with trailing periods are reserved. +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 From 57ec5498641d276fd6875798a1d2bb865056fdcd Mon Sep 17 00:00:00 2001 From: Miraclx Date: Mon, 26 Apr 2021 16:47:57 +0100 Subject: [PATCH 4/4] add tests for trailing periods --- test.js | 3 +++ 1 file changed, 3 insertions(+) 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🐴🐴');