Merge pull request #3796 from JQuinnie/jenns-branch

Allows double dashes in branch name
This commit is contained in:
Brendan Forster 2018-01-24 13:32:24 +11:00 committed by GitHub
commit a05ebffab7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 8 deletions

View file

@ -2,14 +2,11 @@
// ASCII Control chars and space, DEL, ~ ^ : ? * [ \
// | " < and > is technically a valid refname but not on Windows
// the magic sequence @{, consecutive dots, leading and trailing dot, ref ending in .lock
const invalidCharacterRegex = /[\x00-\x20\x7F~^:?*\[\\|""<>]|@{|\.\.+|^\.|\.$|\.lock$|\/$/g
const invalidCharacterRegex = /[\x00-\x20\x7F~^:?*\[\\|""<>]+|@{|\.\.+|^\.|\.$|\.lock$|\/$/g
/** Sanitize a proposed branch name by replacing illegal characters. */
export function sanitizedBranchName(name: string): string {
return name
.replace(invalidCharacterRegex, '-')
.replace(/--+/g, '-')
.replace(/^-/g, '')
return name.replace(invalidCharacterRegex, '-').replace(/^-/g, '')
}
/** Validate a branch does not contain any invalid characters */

View file

@ -39,9 +39,9 @@ describe('sanitizedBranchName', () => {
expect(result).to.equal('first.dot.is.not.ok')
})
it('collapses double dashes', () => {
const branchName = 'branch ? -|name'
it('allows double dashes after first character', () => {
const branchName = 'branch--name'
const result = sanitizedBranchName(branchName)
expect(result).to.equal('branch-name')
expect(result).to.equal(branchName)
})
})