mirror of
https://github.com/desktop/desktop
synced 2024-10-02 14:23:59 +00:00
Merge pull request #3796 from JQuinnie/jenns-branch
Allows double dashes in branch name
This commit is contained in:
commit
a05ebffab7
|
@ -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 */
|
||||
|
|
|
@ -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)
|
||||
})
|
||||
})
|
||||
|
|
Loading…
Reference in a new issue