Skip to content
Open
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Nokogiri follows [Semantic Versioning](https://semver.org/), please see the [REA
### Changed

* The constant `Struct::HTMLElementDescription` is no longer defined. (#3432, #3433) @viralpraxis
* `Document` objects now respond to `#parent`, which will always return `nil`. Previously, the method was `undef`ed from its parent class `Node`. #3466


### Fixed
Expand Down
9 changes: 8 additions & 1 deletion lib/nokogiri/xml/document.rb
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,13 @@ def document
self
end

# call-seq: parent => nil
#
# For a Document, parent always returns +nil+
def parent
nil
end

# :call-seq:
# collect_namespaces() → Hash<String(Namespace#prefix) ⇒ String(Namespace#href)>
#
Expand Down Expand Up @@ -430,7 +437,7 @@ def fragment(tags = nil)
DocumentFragment.new(self, tags, root)
end

undef_method :swap, :parent, :namespace, :default_namespace=
undef_method :swap, :namespace, :default_namespace=
undef_method :add_namespace_definition, :attributes
undef_method :namespace_definitions, :line, :add_namespace

Expand Down
5 changes: 2 additions & 3 deletions test/xml/test_document.rb
Original file line number Diff line number Diff line change
Expand Up @@ -711,9 +711,8 @@ def test_url_kwarg

def test_document_parent
xml = Nokogiri::XML(File.read(XML_FILE), XML_FILE)
assert_raises(NoMethodError) do
xml.parent
end

assert_nil(xml.parent)
end

def test_document_name
Expand Down