Skip to content

Commit

Permalink
Work with ruby 2.3's --enable-frozen-string-literal
Browse files Browse the repository at this point in the history
This is an extension to PR sparklemotion#1412 .
  • Loading branch information
larskanis authored and flavorjones committed Jan 27, 2017
1 parent 2d2893a commit 53f9b66
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 13 deletions.
6 changes: 3 additions & 3 deletions ext/nokogiri/extconf.rb
Original file line number Diff line number Diff line change
Expand Up @@ -223,8 +223,8 @@ def iconv_configure_flags

return [
'--with-iconv=yes',
*("CPPFLAGS=#{idirs.map { |dir| '-I' << dir }.join(' ')}" if idirs),
*("LDFLAGS=#{ldirs.map { |dir| '-L' << dir }.join(' ')}" if ldirs),
*("CPPFLAGS=#{idirs.map { |dir| '-I' + dir }.join(' ')}" if idirs),
*("LDFLAGS=#{ldirs.map { |dir| '-L' + dir }.join(' ')}" if ldirs),
]
end
end
Expand Down Expand Up @@ -307,7 +307,7 @@ def process_recipe(name, version, static_p, cross_p)
if RbConfig::CONFIG['target_cpu'] == 'universal'
%w[CFLAGS LDFLAGS].each do |key|
unless env[key].include?('-arch')
env[key] << ' ' << RbConfig::CONFIG['ARCH_FLAG']
env[key] += ' ' + RbConfig::CONFIG['ARCH_FLAG']
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/nokogiri/xml/node.rb
Original file line number Diff line number Diff line change
Expand Up @@ -623,7 +623,7 @@ def serialize *args, &block
encoding = options[:encoding] || document.encoding
options[:encoding] = encoding

outstring = ""
outstring = String.new
if encoding && outstring.respond_to?(:force_encoding)
outstring.force_encoding(Encoding.find(encoding))
end
Expand Down
13 changes: 6 additions & 7 deletions lib/nokogiri/xml/sax/parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,7 @@ class Attribute < Struct.new(:localname, :prefix, :uri, :value)

# Create a new Parser with +doc+ and +encoding+
def initialize doc = Nokogiri::XML::SAX::Document.new, encoding = 'UTF-8'
check_encoding(encoding)
@encoding = encoding
@encoding = check_encoding(encoding)
@document = doc
@warned = false
end
Expand All @@ -88,9 +87,8 @@ def parse thing, &block
###
# Parse given +io+
def parse_io io, encoding = 'ASCII'
check_encoding(encoding)
@encoding = encoding
ctx = ParserContext.io(io, ENCODINGS[encoding])
@encoding = check_encoding(encoding)
ctx = ParserContext.io(io, ENCODINGS[@encoding])
yield ctx if block_given?
ctx.parse_with self
end
Expand All @@ -114,8 +112,9 @@ def parse_memory data

private
def check_encoding(encoding)
encoding.upcase!
raise ArgumentError.new("'#{encoding}' is not a valid encoding") unless ENCODINGS[encoding]
encoding.upcase.tap do |enc|
raise ArgumentError.new("'#{enc}' is not a valid encoding") unless ENCODINGS[enc]
end
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion test/html/test_document.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def test_nil_css
end

def test_does_not_fail_with_illformatted_html
doc = Nokogiri::HTML('"</html>";'.force_encoding(Encoding::BINARY))
doc = Nokogiri::HTML('"</html>";'.dup.force_encoding(Encoding::BINARY))
assert_not_nil doc
end

Expand Down
2 changes: 1 addition & 1 deletion test/xml/test_document.rb
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ def test_create_comment_with_block
end

def test_pp
out = StringIO.new('')
out = StringIO.new(String.new)
::PP.pp @xml, out
assert_operator out.string.length, :>, 0
end
Expand Down

0 comments on commit 53f9b66

Please sign in to comment.