Skip to content

Commit

Permalink
fix: ensuring gitignored filenames are exact, using $ (#13)
Browse files Browse the repository at this point in the history
  • Loading branch information
mateodelnorte authored and patrickleet committed Jul 18, 2018
1 parent 4054d35 commit b106216
Showing 2 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion __tests__/gitignored.js
Original file line number Diff line number Diff line change
@@ -12,7 +12,7 @@ describe('lib/gitignored', () => {
})

it('.gitignoredRegExpString() returns a string that is a regexp that matches all entries from array', () => {
expect(regExpStr).toBe(`(node_modules|\\.DS_Store|(.+)\\.log|\\.git)`)
expect(regExpStr).toBe(`(node_modules|\\.DS_Store|(.+)\\.log|\\.git)$`)
})

it('.gitignoreRegExp() returns a regexp', () => {
6 changes: 3 additions & 3 deletions lib/gitignored.js
Original file line number Diff line number Diff line change
@@ -17,14 +17,14 @@ module.exports.getGitignored = function(gitignorePath) {
}

const gitignoredRegExpString = function(gitignored) {
return gitignored.reduce((regex, rule, index) => {
return `${gitignored.reduce((regex, rule, index) => {
return index === gitignored.length - 1 ? `${regex}${rule})` : `${regex}${rule}|`
}, '(')
.replace(/\./g, '\\.')
.replace(/\*/g, '(.+)')
.replace(/\*/g, '(.+)')}$`
}
module.exports.gitignoredRegExpString = gitignoredRegExpString

module.exports.gitignoreRegExp = function(gitignored) {
return new RegExp(gitignoredRegExpString(gitignored), 'g')
}
}

0 comments on commit b106216

Please sign in to comment.