Skip to content

Conditions followed by single EOL failed to be processed #4988

Open
@vlada-shubina

Description

@vlada-shubina

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Priority:2Work that is important, but not critical for the releasearea: content-generationRelated to file content generation with operations processing (usually TemplateEngine.Core)bugThe issue describes a bugtriagedThe issue was evaluated by the triage team, placed on correct area, next action defined.

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions