Skip to content

Commit

Permalink
Merge pull request #1767 from kmuto/fix-psych-4
Browse files Browse the repository at this point in the history
Support Ruby 3.1; use YAML.safe_load(_file)
takahashim authored Jan 5, 2022

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
2 parents a79baea + 64d3245 commit f4fc64a
Showing 10 changed files with 18 additions and 17 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ruby-tex.yml
Original file line number Diff line number Diff line change
@@ -13,7 +13,7 @@ jobs:
strategy:
fail-fast: false
matrix:
ruby: [2.5, 3.0]
ruby: ['2.5', '3.0', '3.1']
os: [ubuntu-20.04]
steps:
- uses: actions/checkout@v2
2 changes: 1 addition & 1 deletion .github/workflows/ruby.yml
Original file line number Diff line number Diff line change
@@ -13,7 +13,7 @@ jobs:
strategy:
fail-fast: false
matrix:
ruby: [2.4, 2.5, 2.6, 2.7, 3.0]
ruby: ['2.4', '2.5', '2.6', '2.7', '3.0', '3.1']
os: [ubuntu-latest, macOS-latest]
steps:
- uses: actions/checkout@v2
2 changes: 1 addition & 1 deletion .rubocop.yml
Original file line number Diff line number Diff line change
@@ -410,7 +410,7 @@ Style/CombinableLoops:
### Layout

Layout/BlockAlignment:
Enabled: true
Enabled: false

Layout/EndAlignment:
Enabled: true
2 changes: 1 addition & 1 deletion lib/review/book/base.rb
Original file line number Diff line number Diff line change
@@ -214,7 +214,7 @@ def volume
end

def load_config(filename)
new_conf = YAML.load_file(filename)
new_conf = YAML.safe_load_file(filename, aliases: true, permitted_classes: [Date])
@config.merge!(new_conf)
end

2 changes: 1 addition & 1 deletion lib/review/catalog.rb
Original file line number Diff line number Diff line change
@@ -5,7 +5,7 @@ module ReVIEW
class Catalog
def initialize(file)
if file.respond_to?(:read)
@yaml = YAML.safe_load(file.read, [Date])
@yaml = YAML.safe_load(file.read, aliases: true, permitted_classes: [Date])
else ## as Object
@yaml = file
end
2 changes: 1 addition & 1 deletion lib/review/extentions/string.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
if defined?(Encoding) && Encoding.respond_to?('default_external') &&
if defined?(Encoding) && Encoding.respond_to?(:default_external) &&
Encoding.default_external != Encoding::UTF_8
Encoding.default_external = 'UTF-8'
end
4 changes: 2 additions & 2 deletions lib/review/i18n.rb
Original file line number Diff line number Diff line change
@@ -75,11 +75,11 @@ def load_default
end

def load_file(path)
@store = YAML.load_file(path)
@store = YAML.safe_load_file(path, aliases: true, permitted_classes: [Date])
end

def update_localefile(path)
user_i18n = YAML.load_file(path)
user_i18n = YAML.safe_load_file(path, aliases: true, permitted_classes: [Date])
locale = user_i18n['locale']
if locale
user_i18n.delete('locale')
14 changes: 7 additions & 7 deletions lib/review/update.rb
Original file line number Diff line number Diff line change
@@ -165,7 +165,7 @@ def parse_ymls(dir)

Dir.glob(File.join(dir, '*.yml')).sort.each do |yml|
begin
config = YAML.load_file(yml)
config = YAML.safe_load_file(yml, aliases: true, permitted_classes: [Date])
if config['language'].present?
language = config['language']
end
@@ -238,7 +238,7 @@ def check_own_files(dir)

def update_version
@config_ymls.each do |yml|
config = YAML.load_file(yml)
config = YAML.safe_load_file(yml, aliases: true, permitted_classes: [Date])
if config['review_version'].to_f.round(1) == TARGET_VERSION.to_f.round(1)
next
end
@@ -292,7 +292,7 @@ def update_rakefile(dir)

def update_epub_version
@epub_ymls.each do |yml|
config = YAML.load_file(yml)
config = YAML.safe_load_file(yml, aliases: true, permitted_classes: [Date])
if config['epubversion'].present? && config['epubversion'].to_f < EPUB_VERSION.to_f
if confirm("%s: Update '%s' to '%s' from '%s'?", [File.basename(yml), 'epubversion', EPUB_VERSION, config['epubversion']])
rewrite_yml(yml, 'epubversion', EPUB_VERSION)
@@ -310,7 +310,7 @@ def update_epub_version

def update_locale
@locale_ymls.each do |yml|
config = YAML.load_file(yml)
config = YAML.safe_load_file(yml, aliases: true, permitted_classes: [Date])
if !config['chapter_quote'].present? || config['chapter_quote'].scan('%s').size != 1
next
end
@@ -324,7 +324,7 @@ def update_locale

def update_tex_parameters
@tex_ymls.each do |yml|
config = YAML.load_file(yml)
config = YAML.safe_load_file(yml, aliases: true, permitted_classes: [Date])
unless config['texdocumentclass']
next
end
@@ -510,7 +510,7 @@ def update_tex_stys(template, dir)

def update_tex_command
@tex_ymls.each do |yml|
config = YAML.load_file(yml)
config = YAML.safe_load_file(yml, aliases: true, permitted_classes: [Date])
if !config['texcommand'] || config['texcommand'] !~ /\s+-/
next
end
@@ -535,7 +535,7 @@ def update_tex_command

def update_dvi_command
@tex_ymls.each do |yml|
config = YAML.load_file(yml)
config = YAML.safe_load_file(yml, aliases: true, permitted_classes: [Date])
if !config['dvicommand'] || config['dvicommand'] !~ /\s+-/
next
end
4 changes: 2 additions & 2 deletions lib/review/yamlloader.rb
Original file line number Diff line number Diff line change
@@ -17,8 +17,8 @@ def load_file(yamlfile)

while file_queue.present?
current_file = file_queue.shift
current_yaml = YAML.load_file(current_file)
if current_yaml.instance_of?(FalseClass)
current_yaml = YAML.safe_load_file(current_file, aliases: true, permitted_classes: [Date])
if current_yaml.instance_of?(FalseClass) || current_yaml.nil?
raise "#{File.basename(current_file)} is malformed."
end

1 change: 1 addition & 0 deletions review.gemspec
Original file line number Diff line number Diff line change
@@ -20,6 +20,7 @@ Gem::Specification.new do |gem|
gem.require_paths = ['lib']

gem.add_dependency('image_size')
gem.add_dependency('psych', '3.3.2')
gem.add_dependency('rouge')
gem.add_dependency('rubyzip')
gem.add_dependency('tty-logger')

0 comments on commit f4fc64a

Please sign in to comment.