Skip to content

Commit fd02f1a

Browse files
honeybadgerdontcaretwifkak
authored andcommitted
Do not strip script tags with type=text/plain and template=amp-mustache
PiperOrigin-RevId: 280769508
1 parent 9df4e34 commit fd02f1a

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

transformer/transformers/stripjs.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,13 @@ func StripJS(e *Context) error {
6969
htmlnode.RemoveNode(&n)
7070
}
7171
case "text/plain":
72-
// ok to keep only for children of template (amp-mustache)
73-
if !htmlnode.IsDescendantOf(n, atom.Template) {
74-
htmlnode.RemoveNode(&n)
72+
// ok to keep only when attribute template=amp-mustache is present
73+
if t, ok := htmlnode.GetAttributeVal(n, "", "template"); ok {
74+
if t == "amp-mustache" {
75+
continue
76+
}
7577
}
78+
htmlnode.RemoveNode(&n)
7679
default:
7780
htmlnode.RemoveNode(&n)
7881
}

transformer/transformers/stripjs_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,12 @@ func TestStripJS(t *testing.T) {
6262
Expected: "<head><script type=application/json>foo</script></head><body></body>",
6363
},
6464
{
65-
Desc: "keep type=text/plain when child of template (amp-mustache)",
66-
Input: "<body><template type=amp-mustache><script type=text/plain></script></template></body>",
67-
Expected: "<body><template type=amp-mustache><script type=text/plain></script></template></body>",
65+
Desc: "keep type=text/plain when attribute template=amp-mustache",
66+
Input: "<body><script template=amp-mustache type=text/plain></script></template></body>",
67+
Expected: "<body><script template=amp-mustache type=text/plain></script></template></body>",
6868
},
6969
{
70-
Desc: "strips type=text/plain when not child of template (amp-mustache)",
70+
Desc: "strips type=text/plain when attribute template=amp-mustache is not present",
7171
Input: "<body><script type=text/plain></script></body>",
7272
Expected: "<body></body>",
7373
},

0 commit comments

Comments
 (0)