Skip to content

Commit 9a69908

Browse files
authored
fix: don't split paths on ^ characters (#192)
* fix: don't split paths on `^` characters * chore: add unit tests for toPathComponents util fn * chore: fix lint issues
1 parent f5d3a67 commit 9a69908

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

packages/ipfs-unixfs-importer/src/utils/to-path-components.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ const toPathComponents = (path = '') => {
22
// split on / unless escaped with \
33
return (path
44
.trim()
5-
.match(/([^\\^/]|\\\/)+/g) || [])
5+
.match(/([^\\/]|\\\/)+/g) || [])
66
.filter(Boolean)
77
}
88

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/* eslint-env mocha */
2+
3+
import { expect } from 'aegir/utils/chai.js'
4+
import toPathComponents from '../src/utils/to-path-components.js'
5+
6+
describe('toPathComponents', () => {
7+
it('splits on unescaped "/" characters', () => {
8+
const path = 'foo/bar/baz'
9+
const components = toPathComponents(path)
10+
expect(components.length).to.eq(3)
11+
})
12+
13+
it('does not split on escaped "/" characters', () => {
14+
const path = 'foo\\/bar/baz'
15+
const components = toPathComponents(path)
16+
expect(components.length).to.eq(2)
17+
})
18+
19+
// see https://github.com/ipfs/js-ipfs-unixfs/issues/177 for context
20+
it('does not split on "^" characters', () => {
21+
const path = 'foo/bar^baz^^qux'
22+
const components = toPathComponents(path)
23+
expect(components.length).to.eq(2)
24+
})
25+
})

0 commit comments

Comments
 (0)