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

Implement #clone correctly with respect to singleton classes #3117

Merged
merged 8 commits into from
Feb 2, 2024

Conversation

flavorjones
Copy link
Member

@flavorjones flavorjones commented Jan 31, 2024

What problem is this PR intended to solve?

Fixes #316

Classes this PR updates:

  • XML::Node
  • XML::Document
  • XML::NodeSet

Have you included adequate test coverage?

Yes.

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

The fix applies to both implementations.

@flavorjones flavorjones force-pushed the flavorjones-316-dup-and-clone branch from d9d4b84 to 81a8f14 Compare January 31, 2024 17:39
which unlocks the ability to rely on the Ruby default `#dup` and
`#clone` implementations.
@flavorjones flavorjones force-pushed the flavorjones-316-dup-and-clone branch from 81a8f14 to 253d699 Compare February 1, 2024 16:21
The next commit is going to introduce some layers of indirection to
`#copy` and `#dup` that can raise exceptions, and we need this safety
net in order to avoid segfaults while constructing exception messages.
which unlocks the ability to rely on the Ruby default `#dup` and
`#clone` implementations.
@flavorjones flavorjones force-pushed the flavorjones-316-dup-and-clone branch 2 times, most recently from 62e6361 to 005fe03 Compare February 1, 2024 16:58
@flavorjones flavorjones marked this pull request as ready for review February 1, 2024 19:19
@flavorjones flavorjones force-pushed the flavorjones-316-dup-and-clone branch 3 times, most recently from 1387f66 to 5acd0f3 Compare February 1, 2024 21:29
# [Returns] The new Nokogiri::XML::Document
#
def dup(level = 1)
copy = OBJECT_DUP_METHOD.bind_call(self)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't particularly like the bind_call hack here and in and #clone, but I can't come up with anything better.

@flavorjones flavorjones force-pushed the flavorjones-316-dup-and-clone branch from 5acd0f3 to 7955303 Compare February 1, 2024 22:29
@flavorjones flavorjones merged commit 94a90a0 into main Feb 2, 2024
127 of 128 checks passed
@flavorjones flavorjones deleted the flavorjones-316-dup-and-clone branch February 2, 2024 16:32
flavorjones added a commit that referenced this pull request Feb 2, 2024
…pgrade (#3118)

**What problem is this PR intended to solve?**

- some minor C code cleanup
- improved testing around `Node#dup` that should have been in #3117
- update CI to use `download-artifact` and `upload-artifact` v4

**Have you included adequate test coverage?**

Yes.

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

No functional changes.
@flavorjones flavorjones added this to the v1.17.0 milestone Feb 6, 2024
flavorjones added a commit that referenced this pull request Dec 12, 2024
Back in b92660e (#1834 fixing #1063) I omitted support in JRuby for
the "new_parent_document" argument to `Node#dup` because there was no
performance reason to implement it. So the test was skipped.

However, in 1e7d38a and other commits in #3117 (fixing #316), I
introduced a call to `initialize_copy_with_args` that passes the new
parent document as an argument on both CRuby and JRuby
implementations. Because the test was skipped, I didn't catch that
this broke on JRuby.

In particular this was a problem for Loofah which relies on
decorators, and even more particularly this broke the
`Loofah::TextBehavior` formatting concern for
`Loofah::*::DocumentFragment` objects.

Maybe we should be running downstream tests with JRuby, too? But that
feels like a big investment right now so I'll avoid scarring on the
first cut, and wait to see if it happens again.
flavorjones added a commit that referenced this pull request Dec 12, 2024
Back in b92660e (#1834 fixing #1063) I omitted support in JRuby for
the "new_parent_document" argument to `Node#dup` because there was no
performance reason to implement it. So the test was skipped.

However, in 1e7d38a and other commits in #3117 (fixing #316), I
introduced a call to `initialize_copy_with_args` that passes the new
parent document as an argument on both CRuby and JRuby
implementations. Because the test was skipped, I didn't catch that
this broke on JRuby.

In particular this was a problem for Loofah which relies on
decorators, and even more particularly this broke the
`Loofah::TextBehavior` formatting concern for
`Loofah::*::DocumentFragment` objects.

Maybe we should be running downstream tests with JRuby, too? But that
feels like a big investment right now so I'll avoid scarring on the
first cut, and wait to see if it happens again.

(cherry picked from commit dda0be2)
flavorjones added a commit that referenced this pull request Dec 12, 2024
**What problem is this PR intended to solve?**

Back in b92660e (#1834 fixing #1063) I omitted support in JRuby for the
"new_parent_document" argument to `Node#dup` because there was no
performance reason to implement it. So the test was skipped.

However, in 1e7d38a and other commits in #3117 (fixing #316), I
introduced a call to `initialize_copy_with_args` that passes the new
parent document as an argument on both CRuby and JRuby implementations.
Because the test was skipped, I didn't catch that this broke on JRuby.

In particular this was a problem for Loofah which relies on decorators,
and even more particularly this broke the `Loofah::TextBehavior`
formatting concern for `Loofah::*::DocumentFragment` objects.


**Have you included adequate test coverage?**

The skipped test is no longer skipped!

Maybe we should be running downstream tests with JRuby, too? But that
feels like a big investment right now so I'll avoid scarring on the
first cut, and wait to see if it happens again.


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

Brings the Java impl into agreement with the C impl.
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.

clone & singleton classes
1 participant