Skip to content

Commit

Permalink
fix: don't split paths on ^ characters (#192)
Browse files Browse the repository at this point in the history
* fix: don't split paths on `^` characters

* chore: add unit tests for toPathComponents util fn

* chore: fix lint issues
  • Loading branch information
yusefnapora authored Apr 12, 2022
1 parent f5d3a67 commit 9a69908
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const toPathComponents = (path = '') => {
// split on / unless escaped with \
return (path
.trim()
.match(/([^\\^/]|\\\/)+/g) || [])
.match(/([^\\/]|\\\/)+/g) || [])
.filter(Boolean)
}

Expand Down
25 changes: 25 additions & 0 deletions packages/ipfs-unixfs-importer/test/utils.spec.js
Original file line number Diff line number Diff line change
@@ -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)
})
})

0 comments on commit 9a69908

Please sign in to comment.