mirror of https://github.com/rails/rails
Merge pull request #51631 from heka1024/support-hex-binary
Support hexBinary type in XML
This commit is contained in:
commit
46c41db8fd
|
@ -1,3 +1,7 @@
|
|||
* Support `hexBinary` type in `ActiveSupport::XmlMini`.
|
||||
|
||||
*heka1024*
|
||||
|
||||
* Deprecate `ActiveSupport::ProxyObject` in favor of Ruby's buildin `BasicObject`
|
||||
|
||||
*Earlopain*
|
||||
|
|
|
@ -79,6 +79,7 @@ module ActiveSupport
|
|||
"string" => Proc.new { |string| string.to_s },
|
||||
"yaml" => Proc.new { |yaml| YAML.load(yaml) rescue yaml },
|
||||
"base64Binary" => Proc.new { |bin| ::Base64.decode64(bin) },
|
||||
"hexBinary" => Proc.new { |bin| parse_hex_binary(bin) },
|
||||
"binary" => Proc.new { |bin, entity| _parse_binary(bin, entity) },
|
||||
"file" => Proc.new { |file, entity| _parse_file(file, entity) }
|
||||
}
|
||||
|
@ -162,11 +163,12 @@ module ActiveSupport
|
|||
"#{left}#{middle.tr('_ ', '--')}#{right}"
|
||||
end
|
||||
|
||||
# TODO: Add support for other encodings
|
||||
def _parse_binary(bin, entity)
|
||||
case entity["encoding"]
|
||||
when "base64"
|
||||
::Base64.decode64(bin)
|
||||
when "hex", "hexBinary"
|
||||
parse_hex_binary(bin)
|
||||
else
|
||||
bin
|
||||
end
|
||||
|
@ -180,6 +182,10 @@ module ActiveSupport
|
|||
f
|
||||
end
|
||||
|
||||
def parse_hex_binary(bin)
|
||||
[bin].pack("H*")
|
||||
end
|
||||
|
||||
def current_thread_backend
|
||||
IsolatedExecutionState[:xml_mini_backend]
|
||||
end
|
||||
|
|
|
@ -337,6 +337,19 @@ YAML
|
|||
assert_equal({ "1 => 'test'" => nil }, parser.call("{1 => 'test'}"))
|
||||
end
|
||||
|
||||
def test_hexBinary
|
||||
parser = @parsing["hexBinary"]
|
||||
|
||||
expected = "Hello, World!"
|
||||
hex_binary = "48656C6C6F2C20576F726C6421"
|
||||
|
||||
assert_equal expected, parser.call(hex_binary)
|
||||
|
||||
parser = @parsing["binary"]
|
||||
assert_equal expected, parser.call(hex_binary, "encoding" => "hexBinary")
|
||||
assert_equal expected, parser.call(hex_binary, "encoding" => "hex")
|
||||
end
|
||||
|
||||
def test_base64Binary_and_binary
|
||||
base64 = <<BASE64
|
||||
TWFuIGlzIGRpc3Rpbmd1aXNoZWQsIG5vdCBvbmx5IGJ5IGhpcyByZWFzb24sIGJ1dCBieSB0aGlz
|
||||
|
|
Loading…
Reference in New Issue