From 8c1b389d73af804af7ab7bcf31926aa9678e2617 Mon Sep 17 00:00:00 2001 From: Yusef Napora Date: Mon, 31 Jan 2022 10:35:06 -0500 Subject: [PATCH 1/3] fix: don't split paths on `^` characters --- packages/ipfs-unixfs-importer/src/utils/to-path-components.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/ipfs-unixfs-importer/src/utils/to-path-components.js b/packages/ipfs-unixfs-importer/src/utils/to-path-components.js index 085a53b6..26835e7a 100644 --- a/packages/ipfs-unixfs-importer/src/utils/to-path-components.js +++ b/packages/ipfs-unixfs-importer/src/utils/to-path-components.js @@ -2,7 +2,7 @@ const toPathComponents = (path = '') => { // split on / unless escaped with \ return (path .trim() - .match(/([^\\^/]|\\\/)+/g) || []) + .match(/([^\\/]|\\\/)+/g) || []) .filter(Boolean) } From b99706f7ef1ae2247e9e21609484b3711c0df0be Mon Sep 17 00:00:00 2001 From: Yusef Napora Date: Tue, 29 Mar 2022 12:35:47 -0400 Subject: [PATCH 2/3] chore: add unit tests for toPathComponents util fn --- .../ipfs-unixfs-importer/test/utils.spec.js | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 packages/ipfs-unixfs-importer/test/utils.spec.js diff --git a/packages/ipfs-unixfs-importer/test/utils.spec.js b/packages/ipfs-unixfs-importer/test/utils.spec.js new file mode 100644 index 00000000..dda7f717 --- /dev/null +++ b/packages/ipfs-unixfs-importer/test/utils.spec.js @@ -0,0 +1,25 @@ +/* eslint-env mocha */ + +import { expect } from 'aegir/utils/chai.js' +import toPathComponents from '../src/utils/to-path-components.js' + +describe('toPathComponents', () => { + it('splits on unescaped "/" characters', () => { + const path = 'foo/bar/baz' + const components = toPathComponents(path) + expect(components.length).to.eq(3) + }) + + it('does not split on escaped "/" characters', () => { + const path = 'foo\\/bar/baz' + const components = toPathComponents(path) + expect(components.length).to.eq(2) + }) + + // see https://github.com/ipfs/js-ipfs-unixfs/issues/177 for context + it('does not split on "^" characters', () => { + const path = 'foo/bar^baz^^qux' + const components = toPathComponents(path) + expect(components.length).to.eq(2) + }) +}) \ No newline at end of file From ac450377e670c6848a21697778d62f5fcbb0e9eb Mon Sep 17 00:00:00 2001 From: Yusef Napora Date: Tue, 29 Mar 2022 12:39:14 -0400 Subject: [PATCH 3/3] chore: fix lint issues --- .../ipfs-unixfs-importer/test/utils.spec.js | 34 +++++++++---------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/packages/ipfs-unixfs-importer/test/utils.spec.js b/packages/ipfs-unixfs-importer/test/utils.spec.js index dda7f717..3943bae6 100644 --- a/packages/ipfs-unixfs-importer/test/utils.spec.js +++ b/packages/ipfs-unixfs-importer/test/utils.spec.js @@ -4,22 +4,22 @@ import { expect } from 'aegir/utils/chai.js' import toPathComponents from '../src/utils/to-path-components.js' describe('toPathComponents', () => { - it('splits on unescaped "/" characters', () => { - const path = 'foo/bar/baz' - const components = toPathComponents(path) - expect(components.length).to.eq(3) - }) + it('splits on unescaped "/" characters', () => { + const path = 'foo/bar/baz' + const components = toPathComponents(path) + expect(components.length).to.eq(3) + }) - it('does not split on escaped "/" characters', () => { - const path = 'foo\\/bar/baz' - const components = toPathComponents(path) - expect(components.length).to.eq(2) - }) + it('does not split on escaped "/" characters', () => { + const path = 'foo\\/bar/baz' + const components = toPathComponents(path) + expect(components.length).to.eq(2) + }) - // see https://github.com/ipfs/js-ipfs-unixfs/issues/177 for context - it('does not split on "^" characters', () => { - const path = 'foo/bar^baz^^qux' - const components = toPathComponents(path) - expect(components.length).to.eq(2) - }) -}) \ No newline at end of file + // see https://github.com/ipfs/js-ipfs-unixfs/issues/177 for context + it('does not split on "^" characters', () => { + const path = 'foo/bar^baz^^qux' + const components = toPathComponents(path) + expect(components.length).to.eq(2) + }) +})