Skip to content

Commit

Permalink
Merge pull request #2497 from sparklemotion/flavorjones-update-zlib-b…
Browse files Browse the repository at this point in the history
…ackport-to-v1.13.x

update zlib to v1.2.12 (backport to v1.13.x)
  • Loading branch information
flavorjones authored Apr 5, 2022
2 parents 7d74ced + 9eac631 commit 8c5d485
Show file tree
Hide file tree
Showing 49 changed files with 202 additions and 158 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ jobs:
fail-fast: false
matrix:
sys: ["enable", "disable"]
ruby: ["2.6", "2.7", "3.0", "3.1", "mingw", "head"]
ruby: ["2.6", "2.7", "3.0", "3.1", "mingw"]
runs-on: windows-2022
steps:
- name: configure git crlf
Expand Down
10 changes: 0 additions & 10 deletions .github/workflows/upstream.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,6 @@ concurrency:
cancel-in-progress: true
on:
workflow_dispatch:
push:
branches:
- main
- v*.*.x
tags:
- v*.*.*
pull_request:
types: [opened, synchronize]
branches:
- '*'
schedule:
- cron: "0 8 * * 1,3,5" # At 08:00 on Monday, Wednesday, and Friday # https://crontab.guru/#0_8_*_*_1,3,5

Expand Down
4 changes: 2 additions & 2 deletions dependencies.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ libxslt:
# sha-256 hash provided in https://download.gnome.org/sources/libxslt/1.1/libxslt-1.1.35.sha256sum

zlib:
version: "1.2.11"
sha256: "c3e5e9fdd5004dcb542feda5ee4f0ff0744628baf8ed2dd5d66f8ca1197cb1a1"
version: "1.2.12"
sha256: "91844808532e5ce316b3c010929493c0244f3d37593afd6de04f71821d5136d9"
# SHA-256 hash provided on http://zlib.net/

libiconv:
Expand Down
9 changes: 1 addition & 8 deletions ext/nokogiri/extconf.rb
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,7 @@ def iconv_configure_flags
["iconv", "opt"].each do |target|
config = preserving_globals { dir_config(target) }
next unless config.any? && try_link_iconv("--with-#{target}-* flags") { dir_config(target) }

idirs, ldirs = config.map do |dirs|
Array(dirs).flat_map do |dir|
dir.split(File::PATH_SEPARATOR)
Expand Down Expand Up @@ -715,14 +716,6 @@ def configure
execute("configure",
["env", "CHOST=#{host}", "CFLAGS=#{cflags}", "./configure", "--static", configure_prefix])
end

def compile
if /darwin/.match?(host)
execute("compile", "make AR=#{host}-libtool")
else
super
end
end
end
end
end
Expand Down
2 changes: 2 additions & 0 deletions lib/nokogiri/css/parser_extras.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,14 @@ def set_cache(value) # rubocop:disable Naming/AccessorMethodName
# Get the css selector in +string+ from the cache
def [](string)
return nil unless cache_on?

@mutex.synchronize { @cache[string] }
end

# Set the css selector in +string+ in the cache to +value+
def []=(string, value)
return value unless cache_on?

@mutex.synchronize { @cache[string] = value }
end

Expand Down
6 changes: 4 additions & 2 deletions lib/nokogiri/html4/document.rb
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,9 @@ def set_metadata_element(element) # rubocop:disable Naming/AccessorMethodName
private :set_metadata_element

####
# Serialize Node using +options+. Save options can also be set using a
# block. See SaveOptions.
# Serialize Node using +options+. Save options can also be set using a block.
#
# See also Nokogiri::XML::Node::SaveOptions and Node@Serialization+and+Generating+Output.
#
# These two statements are equivalent:
#
Expand Down Expand Up @@ -241,6 +242,7 @@ def initialize

def start_element(name, attrs = [])
return unless name == "meta"

attr = Hash[attrs]
(charset = attr["charset"]) &&
(@encoding = charset)
Expand Down
2 changes: 2 additions & 0 deletions lib/nokogiri/html4/sax/parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class Parser < Nokogiri::XML::SAX::Parser
def parse_memory(data, encoding = "UTF-8")
raise ArgumentError unless data
return if data.empty?

ctx = ParserContext.memory(data, encoding)
yield ctx if block_given?
ctx.parse_with(self)
Expand All @@ -51,6 +52,7 @@ def parse_file(filename, encoding = "UTF-8")
raise ArgumentError unless filename
raise Errno::ENOENT unless File.exist?(filename)
raise Errno::EISDIR if File.directory?(filename)

ctx = ParserContext.file(filename, encoding)
yield ctx if block_given?
ctx.parse_with(self)
Expand Down
1 change: 1 addition & 0 deletions lib/nokogiri/html5.rb
Original file line number Diff line number Diff line change
Expand Up @@ -468,6 +468,7 @@ def self.escape_text(text, encoding, attribute_mode)

def self.prepend_newline?(node)
return false unless ["pre", "textarea", "listing"].include?(node.name) && !node.children.empty?

first_child = node.children[0]
first_child.text? && first_child.content.start_with?("\n")
end
Expand Down
3 changes: 3 additions & 0 deletions lib/nokogiri/html5/document.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,19 @@ def self.parse(string_or_io, url = nil, encoding = nil, **options, &block)
unless string_or_io.respond_to?(:read) || string_or_io.respond_to?(:to_str)
raise ArgumentError, "not a string or IO object"
end

do_parse(string_or_io, url, encoding, options)
end

def self.read_io(io, url = nil, encoding = nil, **options)
raise ArgumentError, "io object doesn't respond to :read" unless io.respond_to?(:read)

do_parse(io, url, encoding, options)
end

def self.read_memory(string, url = nil, encoding = nil, **options)
raise ArgumentError, "string object doesn't respond to :to_str" unless string.respond_to?(:to_str)

do_parse(string, url, encoding, options)
end

Expand Down
4 changes: 4 additions & 0 deletions lib/nokogiri/html5/node.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,15 @@ module HTML5
module Node
def inner_html(options = {})
return super(options) unless document.is_a?(HTML5::Document)

result = options[:preserve_newline] && HTML5.prepend_newline?(self) ? +"\n" : +""
result << children.map { |child| child.to_html(options) }.join
result
end

def write_to(io, *options)
return super(io, *options) unless document.is_a?(HTML5::Document)

options = options.first.is_a?(Hash) ? options.shift : {}
encoding = options[:encoding] || options[0]
if Nokogiri.jruby?
Expand Down Expand Up @@ -64,6 +66,7 @@ def write_to(io, *options)

def fragment(tags)
return super(tags) unless document.is_a?(HTML5::Document)

DocumentFragment.new(document, tags, self)
end

Expand All @@ -76,6 +79,7 @@ def fragment(tags)
# actually create the xml namespace if it doesn't exist already.
def add_child_node_and_reparent_attrs(node)
return super(node) unless document.is_a?(HTML5::Document)

# I'm not sure what this method is supposed to do. Reparenting
# namespaces is handled by libxml2, including child namespaces which
# this method wouldn't handle.
Expand Down
1 change: 1 addition & 0 deletions lib/nokogiri/version/info.rb
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ def to_markdown
def self.uses_libxml?(requirement = nil)
return false unless VersionInfo.instance.libxml2?
return true unless requirement

Gem::Requirement.new(requirement).satisfied_by?(VersionInfo.instance.loaded_libxml_version)
end

Expand Down
1 change: 1 addition & 0 deletions lib/nokogiri/xml.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ def Reader(string_or_io, url = nil, encoding = nil, options = ParseOptions::STRI
if string_or_io.respond_to?(:read)
return Reader.from_io(string_or_io, url, encoding, options.to_i)
end

Reader.from_memory(string_or_io, url, encoding, options.to_i)
end

Expand Down
2 changes: 2 additions & 0 deletions lib/nokogiri/xml/builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,7 @@ def [](ns)

@parent.ancestors.each do |a|
next if a == doc

@ns = a.namespace_definitions.find { |x| x.prefix == ns.to_s }
return self if @ns
end
Expand Down Expand Up @@ -407,6 +408,7 @@ def method_missing(method, *args, &block) # :nodoc:
if node.namespace.nil?
raise ArgumentError, "Namespace #{@ns[:pending]} has not been defined"
end

@ns = nil
end

Expand Down
5 changes: 5 additions & 0 deletions lib/nokogiri/xml/document.rb
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,7 @@ def decorators(key)
# the document or +nil+ when there is no DTD.
def validate
return nil unless internal_subset

internal_subset.validate(self)
end

Expand Down Expand Up @@ -353,8 +354,10 @@ def slop!
# Apply any decorators to +node+
def decorate(node)
return unless @decorators

@decorators.each do |klass, list|
next unless node.is_a?(klass)

list.each { |moodule| node.extend(moodule) }
end
end
Expand All @@ -380,9 +383,11 @@ def fragment(tags = nil)

def add_child(node_or_tags)
raise "A document may not have multiple root nodes." if (root && root.name != "nokogiri_text_wrapper") && !(node_or_tags.comment? || node_or_tags.processing_instruction?)

node_or_tags = coerce(node_or_tags)
if node_or_tags.is_a?(XML::NodeSet)
raise "A document may not have multiple root nodes." if node_or_tags.size > 1

super(node_or_tags.first)
else
super
Expand Down
10 changes: 8 additions & 2 deletions lib/nokogiri/xml/node.rb
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ def prepend_child(node_or_tags)
if (first = children.first)
# Mimic the error add_child would raise.
raise "Document already has a root node" if document? && !(node_or_tags.comment? || node_or_tags.processing_instruction?)

first.__send__(:add_sibling, :previous, node_or_tags)
else
add_child(node_or_tags)
Expand Down Expand Up @@ -1072,6 +1073,7 @@ def fragment?
# nil on XML documents and on unknown tags.
def description
return nil if document.xml?

Nokogiri::HTML4::ElementDescription[name]
end

Expand Down Expand Up @@ -1119,6 +1121,7 @@ def ancestors(selector = nil)

while parents.last.respond_to?(:parent)
break unless (ctx_parent = parents.last.parent)

parents << ctx_parent
end

Expand Down Expand Up @@ -1150,6 +1153,7 @@ def accept(visitor)
def ==(other)
return false unless other
return false unless other.respond_to?(:pointer_id)

pointer_id == other.pointer_id
end

Expand All @@ -1159,14 +1163,16 @@ def ==(other)
def <=>(other)
return nil unless other.is_a?(Nokogiri::XML::Node)
return nil unless document == other.document

compare(other)
end

# :section: Serialization and Generating Output

###
# Serialize Node using +options+. Save options can also be set using a
# block. See SaveOptions.
# Serialize Node using +options+. Save options can also be set using a block.
#
# See also Nokogiri::XML::Node::SaveOptions and Node@Serialization+and+Generating+Output.
#
# These two statements are equivalent:
#
Expand Down
3 changes: 2 additions & 1 deletion lib/nokogiri/xml/node/save_options.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ module Nokogiri
module XML
class Node
###
# Save options for serializing nodes
# Save options for serializing nodes.
# See the method group entitled Node@Serialization+and+Generating+Output for usage.
class SaveOptions
# Format serialized xml
FORMAT = 1
Expand Down
4 changes: 4 additions & 0 deletions lib/nokogiri/xml/node_set.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ def initialize(document, list = [])
# Get the first element of the NodeSet.
def first(n = nil)
return self[0] unless n

list = []
[n, length].min.times { |i| list << self[i] }
list
Expand Down Expand Up @@ -304,6 +305,7 @@ def to_xml(*args)
# the set is empty
def pop
return nil if length == 0

delete(last)
end

Expand All @@ -312,6 +314,7 @@ def pop
# +nil+ if the set is empty.
def shift
return nil if length == 0

delete(first)
end

Expand All @@ -322,6 +325,7 @@ def shift
def ==(other)
return false unless other.is_a?(Nokogiri::XML::NodeSet)
return false unless length == other.length

each_with_index do |node, i|
return false unless node == other[i]
end
Expand Down
1 change: 1 addition & 0 deletions lib/nokogiri/xml/parse_options.rb
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ def initialize(options = STRICT)

constants.each do |constant|
next if constant.to_sym == :STRICT

class_eval %{
def #{constant.downcase}
@options |= #{constant}
Expand Down
1 change: 1 addition & 0 deletions lib/nokogiri/xml/sax/parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ def parse_file(filename)
raise ArgumentError unless filename
raise Errno::ENOENT unless File.exist?(filename)
raise Errno::EISDIR if File.directory?(filename)

ctx = ParserContext.file(filename)
yield ctx if block_given?
ctx.parse_with(self)
Expand Down
1 change: 1 addition & 0 deletions lib/nokogiri/xml/syntax_error.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ def nil_or_zero?(attribute)

def location_to_s
return nil if nil_or_zero?(line) && nil_or_zero?(column)

"#{line}:#{column}"
end
end
Expand Down
1 change: 1 addition & 0 deletions scripts/test-exported-symbols
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ symbols.to_a.sort.each do |symbol|
next if symbol == "Init_nokogiri"
next if /^Nokogiri_/.match?(symbol)
next if /^noko_/.match?(symbol)

puts "- #{symbol}"
end

Expand Down
3 changes: 3 additions & 0 deletions scripts/test-gem-file-contents
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ gemfile_contents = Dir.mktmpdir do |dir|
unless system("tar -xf #{gemfile} data.tar.gz")
raise "could not unpack gem #{gemfile}"
end

%x(tar -ztf data.tar.gz).split("\n")
end
end
Expand All @@ -47,6 +48,7 @@ gemspec = Dir.mktmpdir do |dir|
unless system("tar -xf #{gemfile} metadata.gz")
raise "could not unpack gem #{gemfile}"
end

YAML.safe_load(%x(gunzip -c metadata.gz), permitted_classes: [Gem::Specification, Gem::Version, Gem::Dependency, Gem::Requirement, Time, Symbol])
end
end
Expand All @@ -72,6 +74,7 @@ describe File.basename(gemfile) do
File.read(cross_rubies_path).split("\n").map do |line|
ver, plat = line.split(":")
next if plat != gemspec.platform.to_s

ver.split(".").take(2).join(".") # ugh
end.compact.uniq.sort
end
Expand Down
2 changes: 2 additions & 0 deletions test/helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ def skip_unless_libxml2_patch(patch_name)
if File.directory?(patch_dir) && !File.exist?(File.join(patch_dir, patch_name))
raise("checking for nonexistent patch file #{patch_name.inspect}")
end

unless Nokogiri.libxml2_patches.include?(patch_name)
skip("this test needs libxml2 patched with #{patch_name}")
end
Expand Down Expand Up @@ -217,6 +218,7 @@ def pending(msg)

def pending_if(msg, pend_eh, &block)
return yield unless pend_eh

pending(msg, &block)
end

Expand Down
Loading

0 comments on commit 8c5d485

Please sign in to comment.