Repository navigation
Description
Examples:
string value = @"Hello
#if (1.2 > 2.5)
#endif
";
string expected = @"Hello
";
byte[] valueBytes = Encoding.UTF8.GetBytes(value);
MemoryStream input = new MemoryStream(valueBytes);
MemoryStream output = new MemoryStream();
VariableCollection vc = new VariableCollection();
IProcessor processor = SetupCStyleNoCommentsProcessor(vc);
//Changes should be made
bool changed = processor.Run(input, output, 50);
Verify(Encoding.UTF8, output, changed, value, expected);
Expected: Hello\r\n
Actual: Hello\r\n#endif\r\n
string value = @"Hello
<!--#if (B)
bar
#endif -->
";
string expected = @"Hello
";
byte[] valueBytes = Encoding.UTF8.GetBytes(value);
MemoryStream input = new MemoryStream(valueBytes);
MemoryStream output = new MemoryStream();
VariableCollection vc = new VariableCollection();
IProcessor processor = SetupXmlStyleProcessor(vc);
//Changes should be made
bool changed = processor.Run(input, output, 50);
Verify(Encoding.UTF8, output, changed, value, expected);;
Expected: Hello\r\n
Actual: Hello\r\n#endif -->\r\n
Some notes:
The case happens when condition is false and ends with empty line.
Then in ProcessorState.Run during HandleMatch for condition the buffer is moved to the end, however not OldestRequiredSequenceNumber for TrieEvaluation.
Due to this, buffer advancing logic proceeds only toOldestRequiredSequenceNumber with offset which is after if condition.
The endif is getting processed once again as unbalanced condition and gets output.
The fix is potentially "accepting" or "finalizes matches" after HandleMatch is done, so last known sequence number is updated and double processing does not happen. Then buffer will be updated to the end and processing stops. After "false" condition branch anyway doesn't make sense to process the open tries. As section is skipped, they won't be matched.
Activity
added test showing the bug: dotnet#4988
added test showing the bug: dotnet#4988
workaround for dotnet#4988
added tests for dotnet#4988; skipped for now
workaround for dotnet#4988
workaround for dotnet#4988
workaround for dotnet#4988
workaround for dotnet#4988
workaround for #4988
added tests for dotnet#4988; skipped for now
added tests for dotnet#4988; skipped for now
tests proving dotnet#4988
tests proving #4988
4 remaining items
aivanov-oneinc commentedon Aug 2, 2023
Having it too with the YAML file. dotnet sdk 7.
Workaround it with adding 2 blank lines at the end of file.
workaround for dotnet/templating#4988
tests proving dotnet/templating#4988
DimitrisKadoglou commentedon Nov 16, 2026
This is still an issue with the .NET 11 SDK. Do we need to create a duplicate Issue in the SDK repo?
DamianEdwards commentedon Nov 16, 2026
FYI @baronfel