diff --git a/parser/v2/raw.go b/parser/v2/raw.go
index 083c2afb6..6cdeed369 100644
--- a/parser/v2/raw.go
+++ b/parser/v2/raw.go
@@ -28,11 +28,17 @@ func (p rawElementParser) Parse(pi *parse.Input) (n Node, ok bool, err error) {
// Element name.
var e RawElement
- if e.Name, ok, err = parse.String(p.name).Parse(pi); err != nil || !ok {
+ if e.Name, ok, err = elementNameParser.Parse(pi); err != nil || !ok {
pi.Seek(start)
return
}
+ if e.Name != p.name {
+ pi.Seek(start)
+ ok = false
+ return
+ }
+
if e.Attributes, ok, err = (attributesParser{}).Parse(pi); err != nil || !ok {
pi.Seek(start)
return
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)
+ }
+ })
+ }
+}