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

Support cloning parser results #186

Open
faisal opened this issue Mar 2, 2024 · 0 comments
Open

Support cloning parser results #186

faisal opened this issue Mar 2, 2024 · 0 comments

Comments

@faisal
Copy link

faisal commented Mar 2, 2024

This is a feature request to match Nokogiri's default behavior of deep-copying when calling dup or clone on the parser result. This behavior is useful when working with parsed source multiple times, since re-parsing each time can get expensive.

Here's a trivial (and currently failing) test case that shows how the two parsers clone:

#!/usr/bin/env ruby

require "nokogiri"
require "oga"
require "minitest/autorun"

class CloningTest < Minitest::Test
  def test_cloning_with_nokogiri
    dom = Nokogiri::HTML5.parse "<html><body></body></html>"
    clone = dom.clone
    clone.at_xpath('/html/body[1]').content = "new"
    
    refute_equal dom.at_xpath('/html/body[1]').content, clone.at_xpath('/html/body[1]').content
  end

  def test_cloning_with_oga
    dom = Oga.parse_html "<html><body></body></html>"
    clone = dom.clone
    clone.at_xpath('/html/body[1]').inner_text = "new"

    refute_equal dom.at_xpath('/html/body[1]').inner_text, clone.at_xpath('/html/body[1]').inner_text
  end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant