Skip to content
Closed
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
11 changes: 9 additions & 2 deletions lib/glob.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,20 @@ class Glob {

// If not a glob pattern then just match the string.
if (!this.glob.includes('*')) {
this.regexp = new RegExp(`.*${this.glob}.*`, 'u')
// Escape special regex characters for non-glob patterns
const escapedGlob = this.escapeRegExp(this.glob)
this.regexp = new RegExp(`.*${escapedGlob}.*`, 'u')
return
}
this.regexptText = this.globize(this.glob)
this.regexp = new RegExp(`^${this.regexptText}$`, 'u')
}

// Helper method to escape special regex characters
escapeRegExp (string) {
return string.replace(/[.*+?^${}()|[\]\\]/g, '\\$&') // $& means the whole matched string
}

globize (glob) {
return glob
.replace(/\\/g, '\\\\') // escape backslashes
Expand Down Expand Up @@ -41,4 +48,4 @@ class Glob {
return s.replaceAll(this.regexp, replacement)
}
}
module.exports = Glob
module.exports = Glob
5 changes: 3 additions & 2 deletions lib/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -298,9 +298,10 @@ ${this.results.reduce((x, y) => {

async updateRepos(repo) {
this.subOrgConfigs = this.subOrgConfigs || await this.getSubOrgConfigs()
let repoConfig = this.config.repository
// Create a fresh copy of the base repository config
let repoConfig = this.config.repository ? Object.assign({}, this.config.repository) : {}
if (repoConfig) {
repoConfig = Object.assign(repoConfig, { name: repo.repo, org: repo.owner })
repoConfig = Object.assign({}, repoConfig, { name: repo.repo, org: repo.owner })
}

const subOrgConfig = this.getSubOrgConfig(repo.repo)
Expand Down
26 changes: 25 additions & 1 deletion test/unit/lib/glob.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,5 +74,29 @@ describe('glob test', function () {
str = 'java/csrf-protection-disabled'
expect(str.search(pattern)>=0).toBeTruthy()
})


test('Test Glob with special regex characters', () => {
// Test for repository names with a period (.)
let pattern = new Glob('.sentry')
let str = '.sentry'
expect(str.search(pattern)>=0).toBeTruthy()
str = 'some-repo'
expect(str.search(pattern)>=0).toBeFalsy()
str = 'other-sentry-repo'
expect(str.search(pattern)>=0).toBeFalsy()

// Test for other special regex characters
pattern = new Glob('repo+name')
str = 'repo+name'
expect(str.search(pattern)>=0).toBeTruthy()
str = 'reponame'
expect(str.search(pattern)>=0).toBeFalsy()

pattern = new Glob('repo[1-3]')
str = 'repo[1-3]'
expect(str.search(pattern)>=0).toBeTruthy()
str = 'repo1'
expect(str.search(pattern)>=0).toBeFalsy()
})

})