lib/builder/xmlbase.rb in builder-3.1.0 vs lib/builder/xmlbase.rb in builder-3.1.1
- old
+ new
@@ -62,11 +62,11 @@
ensure
_indent
_end_tag(sym)
_newline
end
- elsif text.nil?
+ elsif text.nil? || text.empty?
_indent
_start_tag(sym, attrs, true)
_newline
else
_indent
@@ -126,10 +126,12 @@
require 'builder/xchar'
if ::String.method_defined?(:encode)
def _escape(text)
result = XChar.encode(text)
begin
- result.encode(@encoding)
+ encoding = ::Encoding::find(@encoding)
+ raise Exception if encoding.dummy?
+ result.encode(encoding)
rescue
# if the encoding can't be supported, use numeric character references
result.
gsub(/[^\u0000-\u007F]/) {|c| "&##{c.ord};"}.
force_encoding('ascii')