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

Nokogiri::XML::Schema.read_memory() support keyword arguments #3333

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
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
10 changes: 5 additions & 5 deletions lib/nokogiri/xml/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ class << self
# - +parse_options+ (Nokogiri::XML::ParseOptions)
# [Returns] Nokogiri::XML::Schema
#
def Schema(input, parse_options = ParseOptions::DEFAULT_SCHEMA)
Schema.new(input, parse_options)
def Schema(...)
Schema.new(...)
end
end

Expand Down Expand Up @@ -67,8 +67,8 @@ class Schema
#
# [Returns] Nokogiri::XML::Schema
#
def self.new(input, parse_options = ParseOptions::DEFAULT_SCHEMA)
read_memory(input, parse_options)
def self.new(...)
read_memory(...)
end

# :call-seq:
Expand All @@ -86,7 +86,7 @@ def self.new(input, parse_options = ParseOptions::DEFAULT_SCHEMA)
# Defaults to Nokogiri::XML::ParseOptions::DEFAULT_SCHEMA
#
# [Returns] Nokogiri::XML::Schema
def self.read_memory(input, parse_options = ParseOptions::DEFAULT_SCHEMA)
def self.read_memory(input, parse_options_ = ParseOptions::DEFAULT_SCHEMA, parse_options: parse_options_)
from_document(Nokogiri::XML::Document.parse(input), parse_options)
end

Expand Down
30 changes: 30 additions & 0 deletions test/xml/test_schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,16 @@ class TestNokogiriXMLSchema < Nokogiri::TestCase
assert_equal(1, errors.grep(%r{failed to load.*http://localhost:8000/making-a-request}).length)
end

it "XML::Schema parsing attempts to access external DTDs with kwargs" do
doc = Nokogiri::XML::Schema.new(schema, parse_options: Nokogiri::XML::ParseOptions.new.nononet)
errors = doc.errors.map(&:to_s)
assert_empty(
errors.grep(/Attempt to load network entity/),
"Should not see xmlIO.c:xmlNoNetExternalEntityLoader() raising XML_IO_NETWORK_ATTEMPT",
)
assert_equal(1, errors.grep(%r{failed to load.*http://localhost:8000/making-a-request}).length)
end

it "XML::Schema parsing of memory attempts to access external DTDs" do
doc = Nokogiri::XML::Schema.read_memory(schema, Nokogiri::XML::ParseOptions.new.nononet)
errors = doc.errors.map(&:to_s)
Expand All @@ -407,6 +417,16 @@ class TestNokogiriXMLSchema < Nokogiri::TestCase
)
assert_equal(1, errors.grep(%r{failed to load.*http://localhost:8000/making-a-request}).length)
end

it "XML::Schema parsing of memory attempts to access external DTDs with kwargs" do
doc = Nokogiri::XML::Schema.read_memory(schema, parse_options: Nokogiri::XML::ParseOptions.new.nononet)
errors = doc.errors.map(&:to_s)
assert_empty(
errors.grep(/ERROR: Attempt to load network entity/),
"Should not see xmlIO.c:xmlNoNetExternalEntityLoader() raising XML_IO_NETWORK_ATTEMPT",
)
assert_equal(1, errors.grep(%r{failed to load.*http://localhost:8000/making-a-request}).length)
end
end
end

Expand All @@ -429,10 +449,20 @@ class TestNokogiriXMLSchema < Nokogiri::TestCase
assert_equal 0, doc.errors.map(&:to_s).grep(/WARNING: Attempt to load network entity/).length
end

it "XML::Schema parsing attempts to access external DTDs with kwargs" do
doc = Nokogiri::XML::Schema.new(schema, parse_options: Nokogiri::XML::ParseOptions.new.nononet)
assert_equal 0, doc.errors.map(&:to_s).grep(/WARNING: Attempt to load network entity/).length
end

it "XML::Schema parsing of memory attempts to access external DTDs" do
doc = Nokogiri::XML::Schema.read_memory(schema, Nokogiri::XML::ParseOptions.new.nononet)
assert_equal 0, doc.errors.map(&:to_s).grep(/WARNING: Attempt to load network entity/).length
end

it "XML::Schema parsing of memory attempts to access external DTDs with kwargs" do
doc = Nokogiri::XML::Schema.read_memory(schema, parse_options: :XML::ParseOptions.new.nononet)
assert_equal 0, doc.errors.map(&:to_s).grep(/WARNING: Attempt to load network entity/).length
end
end
end
end
Expand Down
Loading