File tree Expand file tree Collapse file tree 2 files changed +26
-1
lines changed
packages/ipfs-unixfs-importer Expand file tree Collapse file tree 2 files changed +26
-1
lines changed Original file line number Diff line number Diff 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 number Diff line number Diff line change 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+ } )
You can’t perform that action at this time.
0 commit comments