From dfe46d79035dd7302bb55b84cc445db07e8dde7f Mon Sep 17 00:00:00 2001 From: Pooya Parsa Date: Thu, 30 Jun 2022 00:49:26 +0200 Subject: [PATCH] fix(extname): handle edge cases wirth leading dot resolves #21 --- src/path.ts | 5 +++-- test/index.spec.ts | 8 ++++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/path.ts b/src/path.ts index f295bd5..0eab07a 100644 --- a/src/path.ts +++ b/src/path.ts @@ -182,9 +182,10 @@ export const toNamespacedPath: typeof path.toNamespacedPath = function (p) { } // extname +const _EXTNAME_RE = /(? 1 ? `.${segments.pop()}` : '' + const match = _EXTNAME_RE.exec(normalizeWindowsPath(p)) + return (match && match[0]) || '' } // relative diff --git a/test/index.spec.ts b/test/index.spec.ts index e3e43e5..05098e6 100644 --- a/test/index.spec.ts +++ b/test/index.spec.ts @@ -61,6 +61,14 @@ runTest('extname', extname, { '/temp/myfile.html': '.html', './myfile.html': '.html', + '.foo': '', + '..foo': '.foo', + 'foo.123': '.123', + '..': '', + '.': '', + './': '', + // '...': '.', // TODO: Edge case behavior of Node? + // Windows 'C:\\temp\\myfile.html': '.html', '\\temp\\myfile.html': '.html',