From 4e107e3ce58452278c3b6b90585e77a160ce45eb Mon Sep 17 00:00:00 2001 From: "Daniel J. Rollins" Date: Thu, 25 Apr 2024 22:09:41 +0100 Subject: [PATCH 1/2] test(parser): add failing test for greedy raw element parser --- parser/v2/raw_test.go | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/parser/v2/raw_test.go b/parser/v2/raw_test.go index 7888e37c3..26de32849 100644 --- a/parser/v2/raw_test.go +++ b/parser/v2/raw_test.go @@ -90,3 +90,36 @@ func TestRawElementParser(t *testing.T) { }) } } + +func TestRawElementParserIsNotGreedy(t *testing.T) { + var tests = []struct { + name string + input string + expected RawElement + }{ + { + name: "styles tag", + input: ``, + }, + { + name: "scripts tag", + input: ``, + }, + } + for _, tt := range tests { + tt := tt + t.Run(tt.name, func(t *testing.T) { + input := parse.NewInput(tt.input) + actual, ok, err := rawElements.Parse(input) + if err != nil { + t.Fatalf("unexpected error: %v", err) + } + if ok { + t.Fatalf("unexpected success for input %q", tt.input) + } + if actual != nil { + t.Fatalf("expected nil Node got %v", actual) + } + }) + } +} From 1bfbec19977b2a52f6aedf115878f11b4e997b04 Mon Sep 17 00:00:00 2001 From: "Daniel J. Rollins" Date: Thu, 25 Apr 2024 22:10:20 +0100 Subject: [PATCH 2/2] fix(parser): use element name parser to extract name for raw parser In the existing code, if the raw element name is successfully parsed, it immediately attempts to parse the attributes, without checking for whitespace or a closing `>`. This means that something like `` would be parsed as a `