diff --git a/Fluid.Tests/ParserTests.cs b/Fluid.Tests/ParserTests.cs index 7625bafd..c1984de0 100644 --- a/Fluid.Tests/ParserTests.cs +++ b/Fluid.Tests/ParserTests.cs @@ -1078,5 +1078,26 @@ public void ShouldContinueForLoop() var template = _parser.Parse(source); Assert.Equal("12345", template.Render()); } + + [Theory] + [InlineData("")] + [InlineData(" ")] + [InlineData(" \n")] + [InlineData(" \n ")] + [InlineData("\n")] + public void ShouldParseLiquidTagWithDifferentSpaces(string spaces) + { + var source = """ + {% liquid + for c in (1..3) + echo c + endforSPACE%}SPACE{{chars}}SPACE + """.Replace("SPACE", spaces); + + var _parser = new FluidParser(); + Assert.True(_parser.TryParse(source, out var template, out var errors), errors); + var rendered = template.Render(); + Assert.Contains("123", rendered); + } } } diff --git a/Fluid/Parser/TagParsers.cs b/Fluid/Parser/TagParsers.cs index 9f637f89..1096d1a5 100644 --- a/Fluid/Parser/TagParsers.cs +++ b/Fluid/Parser/TagParsers.cs @@ -198,28 +198,24 @@ public override bool Parse(ParseContext context, ref ParseResult resu } } - private sealed class OutputTagStartParser : Parser, ISeekable + private sealed class OutputTagStartParser : Parser { public OutputTagStartParser(bool skipWhiteSpace = false) { SkipWhitespace = skipWhiteSpace; } - public bool CanSeek => true; - - public char[] ExpectedChars { get; set; } = ['{']; - public bool SkipWhitespace { get; } public override bool Parse(ParseContext context, ref ParseResult result) { + var start = context.Scanner.Cursor.Position; + if (SkipWhitespace) { context.SkipWhiteSpace(); } - var start = context.Scanner.Cursor.Position; - if (context.Scanner.ReadChar('{') && context.Scanner.ReadChar('{')) { var trim = context.Scanner.ReadChar('-');