Skip to content

Commit

Permalink
prevent Blazor keyword in project name. closes abpframework#9182
Browse files Browse the repository at this point in the history
  • Loading branch information
ebicoglu committed May 28, 2021
1 parent 1a6f094 commit d21fe36
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ public static class ProjectNameValidator
"LPT2"
};

private static readonly string[] IllegalKeywords = new[]
{
"Blazor"
};

private static bool HasParentDirectoryString(string projectName)
{
return projectName.Contains("..");
Expand All @@ -40,6 +45,19 @@ private static bool IsIllegalProjectName(string projectName)
return false;
}

private static bool HasIllegalKeywords(string projectName)
{
foreach (var illegalKeyword in IllegalKeywords)
{
if (projectName.Contains(illegalKeyword))
{
return true;
}
}

return false;
}

public static bool IsValid(string projectName)
{
if (projectName == null)
Expand All @@ -62,6 +80,11 @@ public static bool IsValid(string projectName)
return false;
}

if (HasIllegalKeywords(projectName))
{
return false;
}

return true;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,23 @@ public async Task ParentDirectoryContain_Test()
var args = new CommandLineArgs("new", "Test..Test");
await _newCommand.ExecuteAsync(args).ShouldThrowAsync<CliUsageException>();
}


[Fact]
public async Task Has_Illegel_Keyword_Test()
{
var illegalKeywords = new[]
{
"Acme.Blazor",
"MyBlazor",
};

foreach (var illegalKeyword in illegalKeywords)
{
var args = new CommandLineArgs("new", illegalKeyword);
await _newCommand.ExecuteAsync(args).ShouldThrowAsync<CliUsageException>();
}
}

}
}

0 comments on commit d21fe36

Please sign in to comment.