Skip to content

Commit 1fd9a51

Browse files
Copilotdavidfowl
andcommitted
Remove project name validation - let dotnet new handle validation
Co-authored-by: davidfowl <95136+davidfowl@users.noreply.github.com>
1 parent 6a0e7d3 commit 1fd9a51

File tree

3 files changed

+1
-173
lines changed

3 files changed

+1
-173
lines changed

src/Aspire.Cli/Commands/NewCommand.cs

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
// The .NET Foundation licenses this file to you under the MIT license.
33

44
using System.CommandLine;
5-
using System.Text.RegularExpressions;
65
using Aspire.Cli.Certificates;
76
using Aspire.Cli.Configuration;
87
using Aspire.Cli.DotNet;
@@ -13,7 +12,6 @@
1312
using Aspire.Cli.Templating;
1413
using Aspire.Cli.Utils;
1514
using Semver;
16-
using Spectre.Console;
1715
using NuGetPackage = Aspire.Shared.NuGetPackageCli;
1816

1917
namespace Aspire.Cli.Commands;
@@ -203,9 +201,6 @@ public virtual async Task<string> PromptForProjectNameAsync(string defaultName,
203201
return await interactionService.PromptForStringAsync(
204202
NewCommandStrings.EnterTheProjectName,
205203
defaultValue: defaultName,
206-
validator: name => ProjectNameValidator.IsProjectNameValid(name)
207-
? ValidationResult.Success()
208-
: ValidationResult.Error(NewCommandStrings.InvalidProjectName),
209204
cancellationToken: cancellationToken);
210205
}
211206

@@ -219,21 +214,3 @@ public virtual async Task<ITemplate> PromptForTemplateAsync(ITemplate[] validTem
219214
);
220215
}
221216
}
222-
223-
internal static partial class ProjectNameValidator
224-
{
225-
// Regex for Unicode-aware project name validation:
226-
// - Starts with Unicode letter or number [\p{L}\p{N}]
227-
// - Can contain Unicode letters, numbers, connector punctuation (underscore), dash, dot, and combining marks
228-
// - Must end with Unicode letter or number, optionally followed by combining marks
229-
// - Length: 1-254 characters
230-
// - Excludes unsafe characters: / \ : * ? " < > |
231-
[GeneratedRegex(@"^[\p{L}\p{N}]([\p{L}\p{N}\p{Pc}.\-\p{Mn}\p{Mc}]{0,252}[\p{L}\p{N}][\p{Mn}\p{Mc}]*|[\p{L}\p{N}\p{Pc}.\-\p{Mn}\p{Mc}]{0,252}[\p{L}\p{N}])?$", RegexOptions.Compiled)]
232-
internal static partial Regex GetAssemblyNameRegex();
233-
234-
public static bool IsProjectNameValid(string projectName)
235-
{
236-
var regex = GetAssemblyNameRegex();
237-
return regex.IsMatch(projectName);
238-
}
239-
}

src/Aspire.Cli/Templating/DotNetTemplateFactory.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ private async Task<TemplateResult> ApplyTemplateAsync(CallbackTemplate template,
313313

314314
private async Task<string> GetProjectNameAsync(ParseResult parseResult, CancellationToken cancellationToken)
315315
{
316-
if (parseResult.GetValue<string>("--name") is not { } name || !ProjectNameValidator.IsProjectNameValid(name))
316+
if (parseResult.GetValue<string>("--name") is not { } name)
317317
{
318318
var defaultName = new DirectoryInfo(Environment.CurrentDirectory).Name;
319319
name = await prompter.PromptForProjectNameAsync(defaultName, cancellationToken);

tests/Aspire.Cli.Tests/Commands/ProjectNameValidatorTests.cs

Lines changed: 0 additions & 149 deletions
This file was deleted.

0 commit comments

Comments
 (0)