Skip to content

fix: don't split paths on ^ characters #192

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
})
})