Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ public static IssueFormBody Parse(IssueFormBodyText issueFormBodyText, IssueForm
{
var currentTemplateItem = templateItems[i];
var nextTemplateItem = templateItems.GetNextTemplateElement(i);
var (startIdx, valueLength) = GetLevel3HeaderValueIndexes(currentTemplateItem.Label, nextTemplateItem?.Label, issueFormBodyText);
var (startIdx, valueLength) = GetLevel3HeaderValueIndexes(
currentTemplateItem.Label,
nextTemplateItem?.Label,
issueFormBodyText);
var bodyAsString = (string)issueFormBodyText;
var value = bodyAsString.Substring(startIdx, valueLength);
var issueFormItem = IssueFormItemFactory.CreateFormItem(currentTemplateItem.Id, currentTemplateItem.Type, value);
Expand Down Expand Up @@ -50,9 +53,26 @@ private static (int startIdx, int valueLength) GetLevel3HeaderValueIndexes(
private static int GetStartIndex(this IssueFormBodyText issueFormBodyText, string h3HeaderValue)
{
var bodyAsString = (string)issueFormBodyText;
var startIdx = bodyAsString.IndexOf(h3HeaderValue, StringComparison.Ordinal);
return startIdx is -1
? throw IssueFormBodyParserException.H3HeaderNotFound(h3HeaderValue)
: startIdx;
var h3HeaderValueWindowsLineEnding = h3HeaderValue + NewLines.CR + NewLines.LF;
var startIdx = bodyAsString.IndexOf(h3HeaderValueWindowsLineEnding, StringComparison.Ordinal);
if (startIdx is not -1)
{
return startIdx;
}

var h3HeaderValueUnixLineEnding = h3HeaderValue + NewLines.LF;
startIdx = bodyAsString.IndexOf(h3HeaderValueUnixLineEnding, StringComparison.Ordinal);
if (startIdx is not -1)
{
return startIdx;
}

throw IssueFormBodyParserException.H3HeaderNotFound(h3HeaderValue);
}

internal static class NewLines
{
public const string CR = "\r";
public const string LF = "\n";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ public async Task ParseIssueFormCommandTest1()
/// regardless of the line endings on the issue form body.
/// </summary>
[Theory]
[InlineData(CR)]
[InlineData(LF)]
[InlineData(CR + LF)]
public async Task ParseIssueFormCommandTest2(string newLine)
Expand Down Expand Up @@ -76,4 +75,27 @@ public async Task ParseIssueFormCommandTest2(string newLine)
issueFormJson.OperatingSystems.Unknown.ShouldNotBeNull();
issueFormJson.OperatingSystems.Unknown.ShouldBe(false);
}

/// <summary>
/// Tests that the <see cref="ParseIssueFormCommand"/> produces the expected JSON output.
/// This tests an edge case scenario for matching on the H3 header values. The matching is done
/// with an string.IndexOf method and if two H3 headers start with the same value then the matching
/// would always return the first occurence.
///
/// This has been fixed by changing the matching so that it only matches if the H3 header value
/// matches for an entire line, not just the first string occurence.
/// </summary>
[Fact]
public async Task ParseIssueFormCommandTest3()
{
using var console = new FakeInMemoryConsole();
var command = new ParseIssueFormCommand
{
IssueFormBody = File.ReadAllText("./TestFiles/IssueBody2.md").NormalizeLineEndings(),
TemplateFilepath = "./TestFiles/Template2.yml",
};
await command.ExecuteAsync(console);
var output = console.ReadOutputString();
output.ShouldNotBeNull();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@
<None Update="TestFiles\InvalidTemplate2.yml">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="TestFiles\IssueBody2.md">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="TestFiles\IssueBodyWithMangledCheckbox.md">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
Expand All @@ -60,6 +63,9 @@
<None Update="TestFiles\InvalidTemplate.yml">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="TestFiles\Template2.yml">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="TestFiles\Template.yml">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
### What NuGet package do you want to release?

dotnet-sdk-extensions

### What

dotnet-sdk-extensions-testing
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: Release NuGet package
description: Release a NuGet package.
title: Release NuGet package
body:
- type: dropdown
id: nuget-id
attributes:
label: What NuGet package do you want to release?
options:
- dotnet-sdk-extensions
- dotnet-sdk-extensions-testing
validations:
required: true
- type: dropdown
id: nuget-id-2
attributes:
label: What
options:
- dotnet-sdk-extensions
- dotnet-sdk-extensions-testing
validations:
required: true