!6 Fix occasional failure of rubygem-wikicloth

From: @starlet-dx 
Reviewed-by: @jxy_git 
Signed-off-by: @jxy_git
This commit is contained in:
openeuler-ci-bot 2022-11-16 01:32:32 +00:00 committed by Gitee
commit 4eba451f08
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
2 changed files with 97 additions and 1 deletions

View File

@ -0,0 +1,89 @@
From f683a831cc361438a35c4df3fc7a07d9eab37109 Mon Sep 17 00:00:00 2001
From: katafrakt <inquebrantable@gmail.com>
Date: Sun, 8 Feb 2015 15:52:26 +0100
Subject: [PATCH] make locale change local to wiki rendering
---
lib/wikicloth.rb | 62 +++++++++++++++++++++++++-----------------------
1 file changed, 32 insertions(+), 30 deletions(-)
diff --git a/lib/wikicloth.rb b/lib/wikicloth.rb
index c0ad932..e096c2c 100644
--- a/lib/wikicloth.rb
+++ b/lib/wikicloth.rb
@@ -58,43 +58,45 @@ def load(data,p={})
end
def render(opt={})
- self.options = { :noedit => false, :locale => I18n.default_locale, :fast => true, :output => :html, :link_handler => self.link_handler,
+ self.options = { :noedit => false, :fast => true, :output => :html, :link_handler => self.link_handler,
:params => self.params, :sections => self.sections }.merge(self.options).merge(opt)
self.options[:link_handler].params = options[:params]
- I18n.locale = self.options[:locale]
-
- data = self.sections.collect { |s| s.render(self.options) }.join
- data.gsub!(/<!--(.|\s)*?-->/,"")
- data << "\n" if data.last(1) != "\n"
- data << "garbage"
-
- buffer = WikiBuffer.new("",options)
-
- begin
- if self.options[:fast]
- until data.empty?
- case data
- when /\A\w+/
- data = $'
- @current_row += $&.length
- buffer.add_word($&)
- when /\A[^\w]+(\w|)/m
- data = $'
- $&.each_char { |c| add_current_char(buffer,c) }
+ locale = self.options[:locale] || I18n.locale
+
+ I18n.with_locale(locale) do
+ data = self.sections.collect { |s| s.render(self.options) }.join
+ data.gsub!(/<!--(.|\s)*?-->/,"")
+ data << "\n" if data.last(1) != "\n"
+ data << "garbage"
+
+ buffer = WikiBuffer.new("",options)
+
+ begin
+ if self.options[:fast]
+ until data.empty?
+ case data
+ when /\A\w+/
+ data = $'
+ @current_row += $&.length
+ buffer.add_word($&)
+ when /\A[^\w]+(\w|)/m
+ data = $'
+ $&.each_char { |c| add_current_char(buffer,c) }
+ end
end
+ else
+ data.each_char { |c| add_current_char(buffer,c) }
end
- else
- data.each_char { |c| add_current_char(buffer,c) }
+ rescue => err
+ debug_tree = buffer.buffers.collect { |b| b.debug }.join("-->")
+ puts I18n.t("unknown error on line", :line => @current_line, :row => @current_row, :tree => debug_tree)
+ raise err
end
- rescue => err
- debug_tree = buffer.buffers.collect { |b| b.debug }.join("-->")
- puts I18n.t("unknown error on line", :line => @current_line, :row => @current_row, :tree => debug_tree)
- raise err
- end
- buffer.eof()
- buffer.send("to_#{self.options[:output]}")
+ buffer.eof()
+ buffer.send("to_#{self.options[:output]}")
+ end
end
def sections

View File

@ -1,7 +1,7 @@
%global gem_name wikicloth
Name: rubygem-%{gem_name}
Version: 0.8.0
Release: 2
Release: 3
Summary: Mediawiki parser
License: MIT
URL: https://github.com/nricciar/wikicloth
@ -9,6 +9,9 @@ Source0: https://rubygems.org/gems/wikicloth-%{version}.gem
Patch0: rubygem-wikicloth-0.8.0-minitest.patch
Patch1: rubygem-wikicloth-0.8.3-add-a-condition-to-avoid-FrozenError.patch
Patch2: Fix-build-error.patch
# https://github.com/nricciar/wikicloth/issue/58
# https://github.com/nricciar/wikicloth/pull/79
Patch3: make-locale-change-local-to-wiki-rendering.patch
Requires: ruby(release) ruby(rubygems) rubygem(builder) rubygem(expression_parser)
BuildRequires: ruby(release) rubygems-devel rubygem(activesupport) rubygem(builder)
BuildRequires: rubygem(expression_parser) rubygem(rexml)
@ -31,6 +34,7 @@ gem spec %{SOURCE0} -l --ruby > %{gem_name}.gemspec
%patch0 -p1
%patch1 -p1
%patch2 -p1
%patch3 -p1
for f in .gitignore .travis.yml Gemfile Rakefile run_tests.rb tasks/wikicloth_tasks.rake; do
rm $f
sed -i "s|\"$f\".freeze,||g" %{gem_name}.gemspec
@ -69,6 +73,9 @@ popd
%{gem_instdir}/sample_documents
%changelog
* Tue Nov 15 2022 yaoxin <yaoxin30@h-partners.com> - 0.8.0-3
- Fix occasional failure of rubygem-wikicloth
* Wed Feb 9 2022 yanan li <liyanan32@huawei.com> - 0.8.0-2
- Fix build error