Skip to content

Commit 74aed9c

Browse files
authored
Merge pull request #4668 from joewiz/hotfix/html5-serializer-escaping
[BUG] HTML5 serializer should escape contents of title and textarea elements
2 parents 0c6d524 + 0ebf6f2 commit 74aed9c

File tree

2 files changed

+62
-2
lines changed

2 files changed

+62
-2
lines changed

exist-core/src/main/java/org/exist/util/serializer/HTML5Writer.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,8 +141,6 @@ public class HTML5Writer extends XHTML5Writer {
141141
static {
142142
RAW_TEXT_ELEMENTS.add("script");
143143
RAW_TEXT_ELEMENTS.add("style");
144-
RAW_TEXT_ELEMENTS.add("textarea");
145-
RAW_TEXT_ELEMENTS.add("title");
146144
}
147145

148146
public HTML5Writer() {

exist-core/src/test/xquery/xquery3/serialize.xql

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -865,3 +865,65 @@ function ser:serialize-xml-134() {
865865
}
866866
return serialize((1 to 4)!text{.}, $params)
867867
};
868+
869+
declare
870+
%test:assertEquals('<!DOCTYPE html> <option selected></option>')
871+
function ser:serialize-html-5-boolean-attribute-names() {
872+
let $params := map {
873+
"method" : "html",
874+
"html-version": 5.0
875+
}
876+
return
877+
<option selected="selected"/>
878+
=> serialize($params)
879+
=> normalize-space()
880+
};
881+
882+
declare
883+
%test:assertEquals('<!DOCTYPE html> <br>')
884+
function ser:serialize-html-5-empty-tags() {
885+
let $params := map {
886+
"method" : "html",
887+
"html-version": 5.0
888+
}
889+
return
890+
<br/>
891+
=> serialize($params)
892+
=> normalize-space()
893+
};
894+
895+
declare
896+
%test:assertEquals('<!DOCTYPE html> <foo><style>ul > li { color:red; }</style><script>if (a < b) foo()</script></foo>')
897+
function ser:serialize-html-5-raw-text-elements() {
898+
let $params := map {
899+
"method" : "html",
900+
"html-version": 5.0
901+
}
902+
return
903+
<foo>
904+
<style>{``[ul > li {
905+
color:red;
906+
}]``}</style>
907+
<script>{``[if (a < b) foo()]``}</script>
908+
</foo>
909+
=> serialize($params)
910+
=> normalize-space()
911+
};
912+
913+
declare
914+
%test:assertEquals('<!DOCTYPE html> <foo><title>ul &amp;gt; li { color:red; }</title><textarea>if (a &amp;lt; b) foo()</textarea></foo>')
915+
function ser:serialize-html-5-needs-escape-elements() {
916+
let $params := map {
917+
"method" : "html",
918+
"html-version": 5.0
919+
}
920+
return
921+
<foo>
922+
<title>{``[ul > li {
923+
color:red;
924+
}]``}</title>
925+
<textarea>{``[if (a < b) foo()]``}</textarea>
926+
</foo>
927+
=> serialize($params)
928+
=> normalize-space()
929+
};

0 commit comments

Comments
 (0)