Skip to content

Commit

Permalink
fix: update classname regex to not match leading numbers and special …
Browse files Browse the repository at this point in the history
…characters besides underscore (#6188)

* fix: update classname regex to not match leading numbers and special characters besides underscore

* chore: update changelog

* fix: remove dollar sign and clean up regex

---------

Co-authored-by: Vincent Biret <[email protected]>
  • Loading branch information
Loag and baywet authored Feb 24, 2025
1 parent dd4fbff commit 084f2cf
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Changed

- Fixed mapping of Binary Types to array buffer in TypeScript. [#6124](https://github.com/microsoft/kiota/issues/6124)
- Updated kiota generate classname flag validator to prevent invalid class names. [#6187](https://github.com/microsoft/kiota/issues/6187)

## [1.23.0] - 2025-02-06

Expand Down
2 changes: 1 addition & 1 deletion src/kiota/KiotaHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ private static Option<string> GetManifestOption(string defaultValue)
manifestOption.AddAlias("-a");
return manifestOption;
}
[GeneratedRegex(@"^[a-zA-Z_][\w_-]+", RegexOptions.Singleline, 500)]
[GeneratedRegex(@"^[a-zA-Z_][\w]*", RegexOptions.Singleline, 500)]
private static partial Regex classNameRegex();
[GeneratedRegex(@"^[\w][\w\._-]+", RegexOptions.Singleline, 500)]
private static partial Regex namespaceNameRegex();
Expand Down
3 changes: 3 additions & 0 deletions tests/Kiota.Tests/KiotaHostTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ public async Task ThrowsOnInvalidLogLevelAsync()
public async Task ThrowsOnInvalidClassNameAsync()
{
Assert.Equal(1, await KiotaHost.GetRootCommand().InvokeAsync(["generate", "-c", ".Graph"], _console));
Assert.Equal(1, await KiotaHost.GetRootCommand().InvokeAsync(["generate", "-c", "Graph-api"], _console));
Assert.Equal(1, await KiotaHost.GetRootCommand().InvokeAsync(["generate", "-c", "1Graph"], _console));
Assert.Equal(1, await KiotaHost.GetRootCommand().InvokeAsync(["generate", "-c", "Gr@ph"], _console));
}
[Fact]
public async Task AcceptsDeserializersAsync()
Expand Down

0 comments on commit 084f2cf

Please sign in to comment.