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.