Skip to content

Commit

Permalink
Merge 4464b42 into 0f6c5a0
Browse files Browse the repository at this point in the history
  • Loading branch information
hildjj committed Oct 11, 2022
2 parents 0f6c5a0 + 4464b42 commit 1c88eea
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,23 @@ describe('parseFromFiles', () => {
}])
cfg.should.eql({ foo: 'null' })
})

it('handles minimatch escapables', () => {
// Note that this `#` does not actually test the /^#/ escaping logic,
// because this path will go through a `path.dirname` before that happens.
// It's here to catch what would happen if minimatch started to treat #
// differently inside a pattern.
const bogusPath = path.resolve(__dirname, '#?*+@!()|[]{}')
const escConfigs: editorconfig.ECFile[] = [
{
name: `${bogusPath}/.editorconfig`,
contents: configs[0].contents,
},
]
const escTarget = `${bogusPath}/app.js`
const cfg = editorconfig.parseFromFilesSync(escTarget, escConfigs)
cfg.should.eql(expected)
})
})

describe('parseString', () => {
Expand Down
13 changes: 13 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -207,9 +207,22 @@ function parseFromConfigs(
.reduce(
(matches: Props, file) => {
let pathPrefix = path.dirname(file.name)

if (path.sep !== '/') {
pathPrefix = pathPrefix.replace(escapedSep, '/')
}

// After Windows path backslash's are turned into slashes, so that
// the backslashes we add here aren't turned into forward slashes:

// All of these characters are special to minimatch, but can be
// forced into path names on many file systems. Escape them. Note
// that these are in the order of the case statement in minimatch.
pathPrefix = pathPrefix.replace(/[?*+@!()|[\]{}]/g, '\\$&')
// I can't think of a way for this to happen in the filesystems I've
// seen (because of the path.dirname above), but let's be thorough.
pathPrefix = pathPrefix.replace(/^#/, '\\#')

file.contents.forEach(([glob, options2]) => {
if (!glob) {
return
Expand Down

0 comments on commit 1c88eea

Please sign in to comment.