Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: gumbo support for hr in select #2872

Merged
merged 3 commits into from
May 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,11 @@ You can read more about this in the decision record at `adr/2023-04-libxml-memor
* [CRuby] The C extension now uses Ruby's [TypedData API](https://docs.ruby-lang.org/en/3.0/extension_rdoc.html#label-Encapsulate+C+Data+into+a+Ruby+Object) for managing all the libxml2 structs. Write barriers may improve GC performance in some extreme cases. [[#2808](https://github.com/sparklemotion/nokogiri/issues/2808)] (Thanks, [@etiennebarrie](https://github.com/etiennebarrie) and [@byroot](https://github.com/byroot)!)
* [CRuby] `ObjectSpace.memsize_of` reports a pretty good guess of memory usage when called on `Nokogiri::XML::Document` objects. [[#2807](https://github.com/sparklemotion/nokogiri/issues/2807)] (Thanks, [@etiennebarrie](https://github.com/etiennebarrie) and [@byroot](https://github.com/byroot)!)
* [CRuby] Users installing the "ruby" platform gem and compiling libxml2 and libxslt from source will now be using a modern `config.guess` and `config.sub` that supports new architectures like `loongarch64`. [[#2831](https://github.com/sparklemotion/nokogiri/issues/2831)] (Thanks, [@zhangwenlong8911](https://github.com/zhangwenlong8911)!)
* [CRuby] HTML5 parser now adjusts the specified attributes, adding `xlink:arcrole` and removing `xml:base` [[#2841](https://github.com/sparklemotion/nokogiri/issues/2841), [#2842](https://github.com/sparklemotion/nokogiri/issues/2842)]
* [JRuby] `Node#first_element_child` now returns `nil` if there are only non-element children. [[#2808](https://github.com/sparklemotion/nokogiri/issues/2808), [#2844](https://github.com/sparklemotion/nokogiri/issues/2844)]
* Documentation for `Nokogiri::XSLT` now has usage examples including custom function handlers.
* [CRuby] HTML5 parser:
* adjusts the specified attributes, adding `xlink:arcrole` and removing `xml:base` [[#2841](https://github.com/sparklemotion/nokogiri/issues/2841), [#2842](https://github.com/sparklemotion/nokogiri/issues/2842)]
* allows `<hr>` in `<select>` [[whatwg/html#3410](https://github.com/whatwg/html/issues/3410), [whatwg/html#9124](https://github.com/whatwg/html/pull/9124)]


### Deprecated
Expand Down
12 changes: 12 additions & 0 deletions gumbo-parser/src/parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -3964,6 +3964,18 @@ static void handle_in_select(GumboParser* parser, GumboToken* token) {
insert_element_from_token(parser, token);
return;
}
if (tag_is(token, kStartTag, GUMBO_TAG_HR)) {
if (node_html_tag_is(get_current_node(parser), GUMBO_TAG_OPTION)) {
pop_current_node(parser);
}
if (node_html_tag_is(get_current_node(parser), GUMBO_TAG_OPTGROUP)) {
pop_current_node(parser);
}
insert_element_from_token(parser, token);
pop_current_node(parser);
acknowledge_self_closing_tag(parser);
return;
}
if (tag_is(token, kEndTag, GUMBO_TAG_OPTGROUP)) {
GumboVector* open_elements = &parser->_parser_state->_open_elements;
if (
Expand Down
10 changes: 9 additions & 1 deletion test/html5/test_tree_construction.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,12 @@ def compare_nodes(node, ng_node)
assert_equal(
node[:children].length,
ng_node.children.length,
"Element <#{node[:tag]}> has wrong number of children #{ng_node.children.map(&:name)} in #{@test[:data]}",
[
"Element <#{node[:tag]}> has wrong number of children #{ng_node.children.map(&:name)}",
" Input: #{@test[:data]}",
"Expected: #{@test[:raw].join("\n ")}",
" Parsed: #{ng_node.to_html}",
].join("\n"),
)
when Nokogiri::XML::Node::TEXT_NODE, Nokogiri::XML::Node::CDATA_SECTION_NODE
# We preserve the CDATA in the tree, but the tests represent it as text.
Expand Down Expand Up @@ -205,9 +210,12 @@ def self.parse_test(test_data)
children: [],
}
open_nodes = [document]
test[:raw] = []
while index < lines.length
raise(BadHtml5libFormat, "Expected '| ' but got #{lines[index]}") unless /^\| ( *)([^ ].*$)/ =~ lines[index]

test[:raw] << lines[index]

depth = $LAST_MATCH_INFO[1].length
if depth.odd?
raise(BadHtml5libFormat, "Invalid nesting depth")
Expand Down
2 changes: 1 addition & 1 deletion test/html5lib-tests