diff --git a/ext/nokogiri/xml_node.c b/ext/nokogiri/xml_node.c index a99a6463aae..55fbc084fe4 100644 --- a/ext/nokogiri/xml_node.c +++ b/ext/nokogiri/xml_node.c @@ -1849,13 +1849,19 @@ is_one_of(xmlNodePtr node, char const *const *tagnames, size_t num_tagnames) if (name == NULL) { // fragments don't have a name return false; } + + if (node->ns != NULL) { + // if the node has a namespace, it's in a foreign context and is not one of the HTML tags we're + // matching against. + return false; + } + for (size_t idx = 0; idx < num_tagnames; ++idx) { if (!strcmp(name, tagnames[idx])) { return true; } } return false; - } static void diff --git a/test/html5/test_serialize.rb b/test/html5/test_serialize.rb index a250ec3701a..1d9380d3e5f 100644 --- a/test/html5/test_serialize.rb +++ b/test/html5/test_serialize.rb @@ -553,4 +553,20 @@ def test_serializing_html5_fragment refute(fragment.send(:prepend_newline?)) assert_equal("
hello
goodbye", fragment.to_html) end + + describe "foreign content style tag serialization is escaped" do + it "with svg parent" do + input = %{