!2 fix build error for ruby3

From: @wk333 
Reviewed-by: @small_leek 
Signed-off-by: @small_leek
This commit is contained in:
openeuler-ci-bot 2022-02-22 07:00:07 +00:00 committed by Gitee
commit 8fee4a165d
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
2 changed files with 80 additions and 1 deletions

View File

@ -0,0 +1,71 @@
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

View File

@ -3,14 +3,16 @@
Summary: Really simple JSON and XML parsing, ripped from Merb and Rails Summary: Really simple JSON and XML parsing, ripped from Merb and Rails
Name: rubygem-%{gem_name} Name: rubygem-%{gem_name}
Version: 0.4.2 Version: 0.4.2
Release: 1 Release: 2
License: MIT License: MIT
URL: http://github.com/jnunemaker/crack URL: http://github.com/jnunemaker/crack
Source0: http://rubygems.org/gems/%{gem_name}-%{version}.gem Source0: http://rubygems.org/gems/%{gem_name}-%{version}.gem
Patch0: fix-build-error-for-ruby3.patch
# ruby package has just soft dependency on rubygem(bigdecimal), while # ruby package has just soft dependency on rubygem(bigdecimal), while
# crack always requires it. # crack always requires it.
Requires: rubygem(bigdecimal) Requires: rubygem(bigdecimal)
BuildRequires: rubygems-devel rubygem(bigdecimal) rubygem(minitest) rubygem(safe_yaml) BuildRequires: rubygems-devel rubygem(bigdecimal) rubygem(minitest) rubygem(safe_yaml)
BuildRequires: rubygem-rexml
BuildArch: noarch BuildArch: noarch
#BZ 781829 #BZ 781829
Epoch: 1 Epoch: 1
@ -29,6 +31,9 @@ This package contains documentation for %{name}.
%prep %prep
%setup -q -c -T %setup -q -c -T
%gem_install -n %{SOURCE0} %gem_install -n %{SOURCE0}
pushd .%{gem_instdir}
%patch0 -p1
popd
%build %build
@ -64,5 +69,8 @@ popd
%{gem_instdir}/test %{gem_instdir}/test
%changelog %changelog
* Tue Feb 22 2022 wangkai <wangkai385@huawei.com> - 0.4.2-2
- fix build error for ruby3
* Mon Jul 27 2020 wangxiao <wangxiao65@huawei.com> - 0.4.2-1 * Mon Jul 27 2020 wangxiao <wangxiao65@huawei.com> - 0.4.2-1
- package init - package init