72 lines
2.4 KiB
Diff
72 lines
2.4 KiB
Diff
From 42709c7a30f1e09a32085e3b09820b88c8aa9963 Mon Sep 17 00:00:00 2001
|
|
From: wk333 <13474090681@163.com>
|
|
Date: Thu, 17 Feb 2022 17:54:57 +0800
|
|
Subject: fix build error for ruby3
|
|
|
|
Origin: https://github.com/jnunemaker/crack/commit/579acb39c5597b5a4353181a5cf967c148625275
|
|
Origin: https://github.com/jnunemaker/crack/commit/a7189fef728ce522cb03f62b18848cfc50058245
|
|
|
|
---
|
|
crack.gemspec | 2 +-
|
|
lib/crack/json.rb | 23 +++++------------------
|
|
2 files changed, 6 insertions(+), 19 deletions(-)
|
|
|
|
diff --git a/crack.gemspec b/crack.gemspec
|
|
index 2225c16..5ab19dd 100644
|
|
--- a/crack.gemspec
|
|
+++ b/crack.gemspec
|
|
@@ -16,5 +16,5 @@ Gem::Specification.new do |gem|
|
|
gem.version = Crack::VERSION
|
|
gem.license = "MIT"
|
|
|
|
- gem.add_dependency "safe_yaml", "~> 1.0.0"
|
|
+ gem.add_runtime_dependency("rexml")
|
|
end
|
|
diff --git a/lib/crack/json.rb b/lib/crack/json.rb
|
|
index 7bb890c..39bc620 100644
|
|
--- a/lib/crack/json.rb
|
|
+++ b/lib/crack/json.rb
|
|
@@ -3,34 +3,21 @@
|
|
# The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
|
|
-require 'safe_yaml/load'
|
|
require 'strscan'
|
|
|
|
module Crack
|
|
class JSON
|
|
def self.parser_exceptions
|
|
- @parser_exceptions ||= begin
|
|
- exceptions = [ArgumentError]
|
|
-
|
|
- if const_defined?(:Psych)
|
|
- if Psych.const_defined?(:SyntaxError)
|
|
- exceptions << Psych::SyntaxError
|
|
- end
|
|
- end
|
|
-
|
|
- exceptions
|
|
- end
|
|
+ @parser_exceptions ||= [ArgumentError, Psych::SyntaxError]
|
|
end
|
|
|
|
def self.parse(json)
|
|
- args = [unescape(convert_json_to_yaml(json))]
|
|
- args << nil if SafeYAML::MULTI_ARGUMENT_YAML_LOAD
|
|
- args << { :whitelisted_tags => ['!ruby/regexp'] }
|
|
-
|
|
- SafeYAML.load(*args)
|
|
-
|
|
+ yaml = unescape(convert_json_to_yaml(json))
|
|
+ YAML.safe_load(yaml, [Regexp, Date, Time])
|
|
rescue *parser_exceptions
|
|
raise ParseError, "Invalid JSON string"
|
|
+ rescue Psych::DisallowedClass
|
|
+ yaml
|
|
end
|
|
|
|
protected
|
|
--
|
|
2.27.0
|
|
|