Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conditions followed by single EOL failed to be processed #4988

Open
vlada-shubina opened this issue Jul 19, 2022 · 2 comments
Open

Conditions followed by single EOL failed to be processed #4988

vlada-shubina opened this issue Jul 19, 2022 · 2 comments
Labels
area: content-generation Related to file content generation with operations processing (usually TemplateEngine.Core) bug The issue describes a bug Priority:2 Work that is important, but not critical for the release triaged The issue was evaluated by the triage team, placed on correct area, next action defined.
Milestone

Comments

@vlada-shubina
Copy link
Member

vlada-shubina commented Jul 19, 2022

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.

vlada-shubina added a commit to vlada-shubina/templating that referenced this issue Jul 19, 2022
vlada-shubina added a commit to vlada-shubina/templating that referenced this issue Jul 20, 2022
vlada-shubina added a commit to vlada-shubina/templating that referenced this issue Jul 20, 2022
vlada-shubina added a commit to vlada-shubina/templating that referenced this issue Jul 20, 2022
vlada-shubina added a commit to vlada-shubina/templating that referenced this issue Jul 21, 2022
vlada-shubina added a commit to vlada-shubina/templating that referenced this issue Jul 21, 2022
@vlada-shubina vlada-shubina added the triaged The issue was evaluated by the triage team, placed on correct area, next action defined. label Jul 26, 2022
@vlada-shubina vlada-shubina added this to the Backlog milestone Jul 26, 2022
vlada-shubina added a commit to vlada-shubina/templating that referenced this issue Jul 26, 2022
vlada-shubina added a commit to vlada-shubina/templating that referenced this issue Jul 26, 2022
vlada-shubina added a commit that referenced this issue Jul 26, 2022
vlada-shubina added a commit to vlada-shubina/templating that referenced this issue Aug 26, 2022
vlada-shubina added a commit to vlada-shubina/templating that referenced this issue Aug 26, 2022
vlada-shubina added a commit to vlada-shubina/templating that referenced this issue Sep 14, 2022
vlada-shubina added a commit that referenced this issue Sep 15, 2022
github-actions bot pushed a commit that referenced this issue Oct 11, 2022
vlada-shubina added a commit that referenced this issue Oct 11, 2022
@DamianEdwards
Copy link
Member

I think I'm hitting this issue at the moment building a new project template in ASP.NET Core 8. The Program.cs file has a conditional block at the end of the file and if the condition is false, I end up with a trailing #endif in the output. If I remove the #endif from the template, both conditions "work" but in the false case there are no blank lines at the end of the file. No matter what combination I try I can't get the false case to result in a single blank line at the end of the file (as per our usual standard).

@YuliiaKovalova YuliiaKovalova added bug The issue describes a bug area: content-generation Related to file content generation with operations processing (usually TemplateEngine.Core) Priority:2 Work that is important, but not critical for the release labels May 18, 2023
@aivanov-oneinc
Copy link

aivanov-oneinc commented 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: content-generation Related to file content generation with operations processing (usually TemplateEngine.Core) bug The issue describes a bug Priority:2 Work that is important, but not critical for the release triaged The issue was evaluated by the triage team, placed on correct area, next action defined.
Projects
None yet
Development

No branches or pull requests

4 participants