Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/svg/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby 如何解码svg数据uri(非base64)_Ruby_Svg_Utf 8_Decoding_Data Uri - Fatal编程技术网

Ruby 如何解码svg数据uri(非base64)

Ruby 如何解码svg数据uri(非base64),ruby,svg,utf-8,decoding,data-uri,Ruby,Svg,Utf 8,Decoding,Data Uri,我有svg数据uri: "data:image/svg+xml;charset=utf8,%3Csvgxmlns='http://www.w3.org/2000/svg'width='18'height='36'viewBox='001836'%3E%3Cpathd='M15.70714.293l-2.82-2.82C13.58510.493149.296148c0-3.314-2.686-6-6-6S24.68628s2.686666c1.29602.492-.4153.473-1.113l2

我有svg数据uri:

"data:image/svg+xml;charset=utf8,%3Csvgxmlns='http://www.w3.org/2000/svg'width='18'height='36'viewBox='001836'%3E%3Cpathd='M15.70714.293l-2.82-2.82C13.58510.493149.296148c0-3.314-2.686-6-6-6S24.68628s2.686666c1.29602.492-.4153.473-1.113l2.822.82c.195.195.45.293.707.293.2570.512-.098.707-.293.39-.39.39-1.0230-1.414zM812c-2.2060-4-1.794-4-4s1.794-44-441.79444-1.7944-44z'fill='%23000'/%3E%3Cpathd='M15.70732.293l-2.82-2.82C13.58528.4931427.2961426c0-3.314-2.686-6-6-6s-62.686-662.686666c1.29602.492-.4153.473-1.113l2.822.82c.195.195.45.293.707.293.2570.512-.098.707-.293.39-.39.39-1.0230-1.414zM830c-2.2060-4-1.794-4-4s1.794-44-441.79444-1.7944-44z'fill='red'/%3E%3C/svg%3E"
请帮我把它解码成svg文件。 我使用'data_uri'gem解码base64数据uri没有问题,但是如果我尝试使用优化的url编码,我有一个错误:

ArgumentError:未知编码名称-utf8


这看起来像是URL编码的:

require 'uri'

uri = "data:image/svg+xml;charset=utf8,%3Csvgxmlns='http://www.w3.org/2000/svg'width='18'height='36'viewBox='001836'%3E%3Cpathd='M15.70714.293l-2.82-2.82C13.58510.493149.296148c0-3.314-2.686-6-6-6S24.68628s2.686666c1.29602.492-.4153.473-1.113l2.822.82c.195.195.45.293.707.293.2570.512-.098.707-.293.39-.39.39-1.0230-1.414zM812c-2.2060-4-1.794-4-4s1.794-44-441.79444-1.7944-44z'fill='%23000'/%3E%3Cpathd='M15.70732.293l-2.82-2.82C13.58528.4931427.2961426c0-3.314-2.686-6-6-6s-62.686-662.686666c1.29602.492-.4153.473-1.113l2.822.82c.195.195.45.293.707.293.2570.512-.098.707-.293.39-.39.39-1.0230-1.414zM830c-2.2060-4-1.794-4-4s1.794-44-441.79444-1.7944-44z'fill='red'/%3E%3C/svg%3E"

data = URI.decode(uri.split(',', 2)[1])
puts data
# =>  <svgxmlns='http://www.w3.org/2000/svg'width='18'height='36'viewBox='001836'><pathd='M15.70714.293l-2.82-2.82C13.58510.493149.296148c0-3.314-2.686-6-6-6S24.68628s2.686666c1.29602.492-.4153.473-1.113l2.822.82c.195.195.45.293.707.293.2570.512-.098.707-.293.39-.39.39-1.0230-1.414zM812c-2.2060-4-1.794-4-4s1.794-44-441.79444-1.7944-44z'fill='#000'/><pathd='M15.70732.293l-2.82-2.82C13.58528.4931427.2961426c0-3.314-2.686-6-6-6s-62.686-662.686666c1.29602.492-.4153.473-1.113l2.822.82c.195.195.45.293.707.293.2570.512-.098.707-.293.39-.39.39-1.0230-1.414zM830c-2.2060-4-1.794-4-4s1.794-44-441.79444-1.7944-44z'fill='red'/></svg>
require'uri'
uri=数据:image/svg+xml;字符集=utf8,%3Csvgxmlns=http://www.w3.org/2000/svg7.70714.293.293.293.7.293.7.7.293.7.293.7.7.7.7.7.7.7.7.7.7.297.293.297.297.297.2570.517.517.7-7.297.297.7-7.297.297.7-7.257.517.517.517.517-7.517.517.517-7.517.7-7.7.7.7-7.7.7-7.7.7.7.7 7-7.7 7 7 7.257.7 7 7 7 7 7.7.517.7 7.7 7 7 7 7 7 7 7 7.7 7 7 7 7.7.257.7.517 7.7.517 7 7 7.517.517 7.517 7 7 7 7 7 7 7 7 7 7 7.5.4-1.7944-44z'填充='%23007.58528.417.297.297.297.297.297.297.297.297.297.297.297.293.297.293.257.257.257.257.517.297.297.297.297.297.297.297.297.297.293.257.257.257.257.257.517.517.517-7.517.517.517.517-7.517.5-7-7.517.5-7.517.5-7.5-7.7.7.7.7 7 7 7 7.7.7-7 7 7 7 7 7 7 7 7 7 7-7 7 7 7 7-7.7.7 7 7 7 7 7 7 7 7.7 7 7 7 7 7 7 7 7 7 7 7 7 7 7.7 7 7 7 7 7 7 7 7 7 7 7 7-44z'fill='red'/%3E%3C/svg%3E“
data=URI.decode(URI.split(',,2)[1])
放置数据
# =>  

非常感谢!这就是我要找的东西!:)