Merge pull request #51631 from heka1024/support-hex-binary

Support hexBinary type in XML
This commit is contained in:
Carlos Antonio da Silva 2024-04-23 09:32:59 -03:00 committed by GitHub
commit 46c41db8fd
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 24 additions and 1 deletions

View File

@ -1,3 +1,7 @@
* Support `hexBinary` type in `ActiveSupport::XmlMini`.
*heka1024*
* Deprecate `ActiveSupport::ProxyObject` in favor of Ruby's buildin `BasicObject`
*Earlopain*

View File

@ -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

View File

@ -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