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

fix: Document#initialize should be called exactly once #2174

Merged
merged 5 commits into from
Jan 17, 2021

Conversation

flavorjones
Copy link
Member

What problem is this PR intended to solve?

Originally this PR was started to address errors in Loofah's test suite on JRuby (see flavorjones/loofah#88) related to Nokogiri object decorators not being applied correctly. The root cause of these errors was that {XML,HTML}Document#initialize was not being called in the JRuby implementation. Surprising! And breaks the subclassing behavior that Loofah relies on.

As I erected tests in Nokogiri's suite to make this failure obvious, I uncovered the fact that in CRuby, Document#initialize was actually being called twice from the .parse method. Even more surprising! But doesn't obviously break anything.

This PR addresses both of these issues, with the result that Document#initialize is called exactly once on all platforms.

Have you included adequate test coverage?

Yes! Thorough testing is introduced around subclassing XML::Document, HTML::Document, XML::DocumentFragment, and HTML::DocumentFragment constructor calls .new and .parse.

Does this change affect the behavior of either the C or the Java implementations?

Yes, but as noted above the changed behavior is now correct and consistent across the platforms.

Also update {xml,html}/test_document_fragment.rb with rubocop format
and minispec "describe" wrapper.
This was noticed while debugging some Loofah behavior that relied on
overriding `#initialize` to decorate nodes.

Related to flavorjones/loofah#88
This is a prefactor for the upcoming commit.
Previously #initialize was being called twice from Document.parse
@codeclimate
Copy link

codeclimate bot commented Jan 17, 2021

Code Climate has analyzed commit 30c3a57 and detected 0 issues on this pull request.

The test coverage on the diff in this pull request is 100.0% (80% is the threshold).

This pull request will bring the total coverage in the repository to 94.3% (0.0% change).

View more on Code Climate.

Base automatically changed from master to main January 17, 2021 21:53
@flavorjones flavorjones merged commit d79c2d0 into main Jan 17, 2021
@flavorjones flavorjones deleted the flavorjones-fix-java-decorators branch January 17, 2021 21:56
@flavorjones flavorjones added this to the v1.11.x patch releases milestone Jan 18, 2021
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

Successfully merging this pull request may close these issues.

1 participant