mirror of
https://github.com/microsoft/PowerToys.git
synced 2025-12-16 11:48:06 +01:00
Validate names for invalid for C# namespaces in cmdpal (#39401)
## Summary of the Pull Request The Command Palette allows users to create extensions with dashes in their names, which is invalid for C# namespaces. This causes projects to fail during build because the name cannot be used as a valid namespace. ## Changes - Updated the validation regex in `NewExtensionForm.cs` to only allow valid C# identifiers - Now only allows names starting with a letter or underscore, followed by letters, numbers, or underscores - Explicitly prevents dashes, spaces, and other special characters - Improved the error message to clearly explain the requirements for valid C# identifiers ## Before Previously, the input only validated that no spaces were used: ```csharp "regex": "^[^\\s]+$" ``` ## After Now the input properly validates for C# namespace compatibility: ```csharp "regex": "^[a-zA-Z_][a-zA-Z0-9_]*$" ``` This ensures that users cannot create extension projects with names that would fail to build. ## PR Checklist - [ ] **Closes:** https://github.com/microsoft/PowerToys/issues/38522
This commit is contained in:
@@ -55,7 +55,7 @@ internal sealed partial class NewExtensionForm : NewExtensionFormBase
|
|||||||
"errorMessage": {{FormatJsonString(Properties.Resources.builtin_create_extension_name_required)}},
|
"errorMessage": {{FormatJsonString(Properties.Resources.builtin_create_extension_name_required)}},
|
||||||
"id": "ExtensionName",
|
"id": "ExtensionName",
|
||||||
"placeholder": "ExtensionName",
|
"placeholder": "ExtensionName",
|
||||||
"regex": "^[^\\s]+$"
|
"regex": "^[a-zA-Z_][a-zA-Z0-9_]*$"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"type": "TextBlock",
|
"type": "TextBlock",
|
||||||
|
|||||||
@@ -178,7 +178,7 @@ namespace Microsoft.CmdPal.UI.ViewModels.Properties {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Looks up a localized string similar to Extension name is required, without spaces.
|
/// Looks up a localized string similar to Extension name is required and must be a valid C# identifier (start with a letter or underscore, followed by letters, numbers, or underscores).
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static string builtin_create_extension_name_required {
|
public static string builtin_create_extension_name_required {
|
||||||
get {
|
get {
|
||||||
|
|||||||
@@ -195,7 +195,7 @@
|
|||||||
<value>Extension name</value>
|
<value>Extension name</value>
|
||||||
</data>
|
</data>
|
||||||
<data name="builtin_create_extension_name_required" xml:space="preserve">
|
<data name="builtin_create_extension_name_required" xml:space="preserve">
|
||||||
<value>Extension name is required, without spaces</value>
|
<value>Extension name is required and must be a valid C# identifier (start with a letter or underscore, followed by letters, numbers, or underscores)</value>
|
||||||
</data>
|
</data>
|
||||||
<data name="builtin_create_extension_display_name_header" xml:space="preserve">
|
<data name="builtin_create_extension_display_name_header" xml:space="preserve">
|
||||||
<value>Display name</value>
|
<value>Display name</value>
|
||||||
|
|||||||
Reference in New Issue
Block a user