Skip to content
This repository was archived by the owner on Dec 5, 2024. It is now read-only.

Commit 1d2ab9f

Browse files
Correcting unit tests
1 parent a5aae89 commit 1d2ab9f

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

src/GitHub.Api/Helpers/RegularExpressions.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,22 @@ namespace GitHub.Unity.Helpers
44
{
55
public static class RegularExpressions
66
{
7-
public static readonly Regex BranchNameRegex = new Regex(@"^(?<name>[\w\d\/\-_]+)$");
7+
public static readonly Regex BranchNameRegex = new Regex(@"^(?<name>[\.\w\d\/\-_]+)$");
88
}
99

1010
public static class BranchNameValidator
1111
{
1212
public static bool IsBranchNameValid(string branchName)
1313
{
1414
return !string.IsNullOrEmpty(branchName)
15+
&& !branchName.Equals(".")
1516
&& !branchName.StartsWith("/")
1617
&& !branchName.EndsWith("/")
18+
&& !branchName.EndsWith(".")
19+
&& !branchName.Contains("//")
20+
&& !branchName.Contains(@"\")
21+
&& !branchName.EndsWith(".lock")
22+
&& !(branchName.StartsWith(".") && branchName.Contains("/"))
1723
&& RegularExpressions.BranchNameRegex.IsMatch(branchName);
1824
}
1925
}

src/tests/UnitTests/Git/BranchNameValidationTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public class BranchNameValidatorTests
2828
[TestCase(false, "@", TestName = "Single character cannot be @")]
2929
[TestCase(false, ".", TestName = "Single character cannot be [period]")]
3030
[TestCase(true, "features/feature-1", TestName = "Folder and branch name is valid")]
31-
[TestCase(true, "features\\feature-1", TestName = "Backslash is not a valid character")]
31+
[TestCase(false, @"features\feature-1", TestName = "Backslash is not a valid character")]
3232
[TestCase(true, ".hidden", TestName = "Branch name is valid when starting with [period]")]
3333
[TestCase(false, ".features/feature-1", TestName = "Folder and branch name is not valid when starting with [period]")]
3434
[TestCase(false, "features//feature-1", TestName = "Multiple consecutive slashes are not valid")]

0 commit comments

Comments
 (0)