diff --git a/CHANGELOG.md b/CHANGELOG.md index 2da8bb4080..7649b49a9c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Fixed python generation in scenarios with opening/closing tags for code comments. [#5636](https://github.com/microsoft/kiota/issues/5636) - Fixed Python error when a class inherits from a base class and implements an interface. [5637](https://github.com/microsoft/kiota/issues/5637) - Fix anyOf/oneOf generation in TypeScript. [5353](https://github.com/microsoft/kiota/issues/5353) +- Fixed invalid code in Php caused by "*/*/" in property description. [5635](https://github.com/microsoft/kiota/issues/5635) ## [1.20.0] - 2024-11-07 diff --git a/it/config.json b/it/config.json index 6295abf3cb..dab857bc52 100644 --- a/it/config.json +++ b/it/config.json @@ -33,13 +33,13 @@ "Language": "typescript", "Rationale": "https://github.com/microsoft/kiota/issues/5634" }, - { - "Language": "php", - "Rationale": "https://github.com/microsoft/kiota/issues/5635" - }, { "Language": "ruby", "Rationale": "https://github.com/microsoft/kiota/issues/1816" + }, + { + "Language": "php", + "Rationale": "https://github.com/microsoft/kiota/issues/5779" } ], "ExcludePatterns": [ @@ -259,4 +259,4 @@ "Suppressions": [], "IdempotencySuppressions": [] } -} \ No newline at end of file +} diff --git a/src/Kiota.Builder/Writers/Php/CodeEnumWriter.cs b/src/Kiota.Builder/Writers/Php/CodeEnumWriter.cs index b85e876273..cd6789a8fa 100644 --- a/src/Kiota.Builder/Writers/Php/CodeEnumWriter.cs +++ b/src/Kiota.Builder/Writers/Php/CodeEnumWriter.cs @@ -47,7 +47,7 @@ public override void WriteCodeElement(CodeEnum codeElement, LanguageWriter write writer.IncreaseIndent(); foreach (var enumProperty in enumProperties) { - writer.WriteLine($"public const {GetEnumValueName(enumProperty.Name)} = '{enumProperty.WireName}';"); + writer.WriteLine($"public const {GetEnumValueName(enumProperty.Name)} = \"{enumProperty.WireName}\";"); } } [GeneratedRegex(@"([A-Z]{1})", RegexOptions.Singleline, 500)] diff --git a/src/Kiota.Builder/Writers/Php/PhpConventionService.cs b/src/Kiota.Builder/Writers/Php/PhpConventionService.cs index 67cee78295..230fa1b527 100644 --- a/src/Kiota.Builder/Writers/Php/PhpConventionService.cs +++ b/src/Kiota.Builder/Writers/Php/PhpConventionService.cs @@ -135,7 +135,7 @@ private string GetCollectionDocString(CodeParameter codeParameter) return codeParameter.Optional ? $"{doc}|null" : doc; } - internal static string RemoveInvalidDescriptionCharacters(string originalDescription) => originalDescription.Replace("\\", "/", StringComparison.OrdinalIgnoreCase); + internal static string RemoveInvalidDescriptionCharacters(string originalDescription) => originalDescription.Replace("\\", "/", StringComparison.OrdinalIgnoreCase).Replace("*/", string.Empty, StringComparison.OrdinalIgnoreCase); public override bool WriteShortDescription(IDocumentedElement element, LanguageWriter writer, string prefix = "", string suffix = "") { ArgumentNullException.ThrowIfNull(writer); diff --git a/tests/Kiota.Builder.Tests/Writers/Php/CodeEnumWriterTests.cs b/tests/Kiota.Builder.Tests/Writers/Php/CodeEnumWriterTests.cs index 62ce1a24ec..609434152f 100644 --- a/tests/Kiota.Builder.Tests/Writers/Php/CodeEnumWriterTests.cs +++ b/tests/Kiota.Builder.Tests/Writers/Php/CodeEnumWriterTests.cs @@ -52,7 +52,7 @@ public async Task WritesEnumAsync() Assert.Contains("use Microsoft\\Kiota\\Abstractions\\Enum", result); Assert.Contains("class", result); Assert.Contains("extends Enum", result); - Assert.Contains($"public const {optionName.ToUpperInvariant()} = '{optionName}'", result); + Assert.Contains($"public const {optionName.ToUpperInvariant()} = \"{optionName}\"", result); AssertExtensions.CurlyBracesAreClosed(result, 1); Assert.Contains(optionName, result); } diff --git a/tests/Kiota.Builder.Tests/Writers/Php/CodePropertyWriterTests.cs b/tests/Kiota.Builder.Tests/Writers/Php/CodePropertyWriterTests.cs index a00225e813..4b96585405 100644 --- a/tests/Kiota.Builder.Tests/Writers/Php/CodePropertyWriterTests.cs +++ b/tests/Kiota.Builder.Tests/Writers/Php/CodePropertyWriterTests.cs @@ -246,4 +246,26 @@ public async Task WriteRequestOptionAsync() Assert.Contains("@var array|null $options", result); Assert.Contains("public ?array $options = null;", result); } + + [Fact] + public void WritePropertyWithDescription() + { + CodeProperty property = new CodeProperty + { + Name = "name", + Documentation = new() + { + DescriptionTemplate = "The name pattern that branches must match in order to deploy to the environment.Wildcard characters will not match `/`. For example, to match branches that begin with `release/` and contain an additional single slash, use `release/*/*`.For more information about pattern matching syntax, see the [Ruby File.fnmatch documentation](https://ruby-doc.org/core-2.5.1/File.html#method-c-fnmatch).", + }, + Type = new CodeType + { + Name = "string" + }, + Access = AccessModifier.Private + }; + parentClass.AddProperty(property); + propertyWriter.WriteCodeElement(property, languageWriter); + var result = stringWriter.ToString(); + Assert.DoesNotContain("/*/*", result); + } }