-
Notifications
You must be signed in to change notification settings - Fork 715
Simplify Aspire CLI project name validation to only reject path separators #10714
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
c5ed9a2
ca1a26f
6a0e7d3
1fd9a51
020c076
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,171 @@ | ||||||
| // Licensed to the .NET Foundation under one or more agreements. | ||||||
| // The .NET Foundation licenses this file to you under the MIT license. | ||||||
|
|
||||||
| using Aspire.Cli.Commands; | ||||||
|
|
||||||
| namespace Aspire.Cli.Tests.Commands; | ||||||
|
|
||||||
| public class ProjectNameValidatorTests | ||||||
| { | ||||||
| [Theory] | ||||||
| [InlineData("项目1", true)] // Chinese | ||||||
| [InlineData("Проект1", true)] // Cyrillic | ||||||
| [InlineData("プロジェクト1", true)] // Japanese | ||||||
| [InlineData("مشروع1", true)] // Arabic | ||||||
| [InlineData("Project_1", true)] // Latin with underscore | ||||||
| [InlineData("Project-1", true)] // Latin with dash | ||||||
| [InlineData("Project.1", true)] // Latin with dot | ||||||
| [InlineData("MyApp", true)] // Simple ASCII | ||||||
| [InlineData("A", true)] // Single character | ||||||
| [InlineData("1", true)] // Single number | ||||||
| [InlineData("プ", true)] // Single Unicode character | ||||||
| [InlineData("Test123", true)] // Mixed letters and numbers | ||||||
| [InlineData("My_Cool-Project.v2", true)] // Complex valid name | ||||||
| [InlineData("Project:1", true)] // Colon (now allowed) | ||||||
| [InlineData("Project*1", true)] // Asterisk (now allowed) | ||||||
| [InlineData("Project?1", true)] // Question mark (now allowed) | ||||||
| [InlineData("Project\"1", true)] // Quote (now allowed) | ||||||
| [InlineData("Project<1", true)] // Less than (now allowed) | ||||||
| [InlineData("Project>1", true)] // Greater than (now allowed) | ||||||
| [InlineData("Project|1", true)] // Pipe (now allowed) | ||||||
| [InlineData("Project ", true)] // Ends with space (now allowed) | ||||||
| [InlineData(" Project", true)] // Starts with space (now allowed) | ||||||
| [InlineData("Pro ject", true)] // Space in middle (now allowed) | ||||||
| [InlineData("-Project", true)] // Starts with dash (now allowed) | ||||||
| [InlineData("Project-", true)] // Ends with dash (now allowed) | ||||||
| [InlineData(".Project", true)] // Starts with dot (now allowed) | ||||||
| [InlineData("Project.", true)] // Ends with dot (now allowed) | ||||||
| [InlineData("_Project", true)] // Starts with underscore (now allowed) | ||||||
| [InlineData("Project_", true)] // Ends with underscore (now allowed) | ||||||
| public void IsProjectNameValid_ValidNames_ReturnsTrue(string projectName, bool expected) | ||||||
| { | ||||||
| // Act | ||||||
| var result = ProjectNameValidator.IsProjectNameValid(projectName); | ||||||
|
|
||||||
| // Assert | ||||||
| Assert.Equal(expected, result); | ||||||
| } | ||||||
|
|
||||||
| [Theory] | ||||||
| [InlineData("Project/1", false)] // Forward slash (path separator) | ||||||
| [InlineData("Project\\1", false)] // Backslash (path separator) | ||||||
| [InlineData("", false)] // Empty string | ||||||
| [InlineData(" ", false)] // Space only | ||||||
|
||||||
| [InlineData(" ", false)] // Multiple spaces only | ||||||
|
||||||
| [InlineData(" ", false)] // Multiple spaces only | |
| [InlineData(" ", true)] // Multiple spaces only |
Copilot
AI
Aug 5, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test case expects tab-only strings to be invalid, but the regex ^[^/\\]{1,254}$ will match tabs since tab is not a path separator. The test expectation contradicts the actual regex behavior.
| [InlineData("\t", false)] // Tab only | |
| [InlineData("\t", true)] // Tab only |
Copilot
AI
Aug 5, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test case expects newline-only strings to be invalid, but the regex ^[^/\\]{1,254}$ will match newlines since newline is not a path separator. The test expectation contradicts the actual regex behavior.
| [InlineData("\n", false)] // Newline only | |
| [InlineData("\n", true)] // Newline only |
Uh oh!
There was an error while loading. Please reload this page.