File tree 2 files changed +26
-1
lines changed
packages/ipfs-unixfs-importer
2 files changed +26
-1
lines changed Original file line number Diff line number Diff line change @@ -2,7 +2,7 @@ const toPathComponents = (path = '') => {
2
2
// split on / unless escaped with \
3
3
return ( path
4
4
. trim ( )
5
- . match ( / ( [ ^ \\ ^ / ] | \\ \/ ) + / g) || [ ] )
5
+ . match ( / ( [ ^ \\ / ] | \\ \/ ) + / g) || [ ] )
6
6
. filter ( Boolean )
7
7
}
8
8
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