Skip to content

Commit b28e9c8

Browse files
authored
Fix multiline see tags in XML documentation (#3435)
Fix `HumanizeHrefTags` not working when see tag spans over multiple lines.
1 parent 3390173 commit b28e9c8

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

src/Swashbuckle.AspNetCore.SwaggerGen/XmlComments/XmlCommentsTextHelper.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ internal static string EndOfLine(string xmlCommentEndOfLine)
219219
private const string CodeTagPattern = @"<c>(?<display>.+?)</c>";
220220
private const string MultilineCodeTagPattern = @"<code>(?<display>.+?)</code>";
221221
private const string ParaTagPattern = @"<para>(?<display>.+?)</para>";
222-
private const string HrefPattern = @"<see href=\""(.*)\"">(.*)<\/see>";
222+
private const string HrefPattern = @"<see\s+href=\""([^""]*)\"">\s*(.*?)\s*<\/see>";
223223
private const string BrPattern = @"(<br ?\/?>)"; // handles <br>, <br/>, <br />
224224
private const string LineBreaksPattern = @"\r?\n";
225225
private const string DoubleUpLineBreaksPattern = @"(\r?\n){2,}";
@@ -237,7 +237,7 @@ internal static string EndOfLine(string xmlCommentEndOfLine)
237237
[GeneratedRegex(ParaTagPattern, RegexOptions.Singleline)]
238238
private static partial Regex ParaTag();
239239

240-
[GeneratedRegex(HrefPattern)]
240+
[GeneratedRegex(HrefPattern, RegexOptions.Singleline)]
241241
private static partial Regex HrefTag();
242242

243243
[GeneratedRegex(BrPattern)]

test/Swashbuckle.AspNetCore.SwaggerGen.Test/XmlComments/XmlCommentsTextHelperTests.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,19 @@ public void Humanize_HumanizesInlineTags(
142142
Assert.Equal(expectedOutput, output, false, true);
143143
}
144144

145+
[Fact]
146+
public void Humanize_SeeMultiLineTag()
147+
{
148+
const string input = @"
149+
<see href=""https://www.iso.org/iso-4217-currency-codes.html"">
150+
ISO currency code
151+
</see>";
152+
153+
var output = XmlCommentsTextHelper.Humanize(input);
154+
155+
Assert.Equal("[ISO currency code](https://www.iso.org/iso-4217-currency-codes.html)", output, false, true);
156+
}
157+
145158
[Theory]
146159
[InlineData("\r\n")]
147160
[InlineData("\n")]

0 commit comments

Comments
 (0)