Skip to content

Conditions followed by single EOL failed to be processed #4988

Open
dotnet/sdk
#57156

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.

Activity

  1. added
    triagedThe issue was evaluated by the triage team, placed on correct area, next action defined.
    on Jul 26, 2022
  2. added this to the Backlog milestone on Jul 26, 2022
  3. added 2 commits that reference this issue on Aug 26, 2022
  4. 4 remaining items

  5. added
    area: content-generationRelated to file content generation with operations processing (usually TemplateEngine.Core)
    Priority:2Work that is important, but not critical for the release
    on May 18, 2023
  6. aivanov-oneinc commented on Aug 2, 2023

    @aivanov-oneinc

    Having it too with the YAML file. dotnet sdk 7.
    Workaround it with adding 2 blank lines at the end of file.

  7. DimitrisKadoglou commented on Nov 16, 2026

    @DimitrisKadoglou

    This is still an issue with the .NET 11 SDK. Do we need to create a duplicate Issue in the SDK repo?

  8. DamianEdwards commented on Nov 16, 2026

    @DamianEdwards
    Member
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

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 bugtriage:transfer-to-sdkIssue should be transferred to dotnet/sdktriagedThe 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