Skip to content

Commit eb45c5a

Browse files
committed
Read project text files as UTF-8
1 parent 0c6b2eb commit eb45c5a

27 files changed

Lines changed: 56 additions & 53 deletions

Rakefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ task :coverage_check do
6060
spec_tags = Set.new
6161
Dir.glob(File.join(base, "specs/**/*.yml")).each do |f|
6262
begin
63-
data = YAML.safe_load(File.read(f), permitted_classes: [Symbol, Range], aliases: true)
63+
data = YAML.safe_load(File.read(f, encoding: Encoding::UTF_8), permitted_classes: [Symbol, Range], aliases: true)
6464
next unless data
6565

6666
meta = data.is_a?(Hash) ? (data["_metadata"] || {}) : {}
@@ -80,7 +80,7 @@ task :coverage_check do
8080
adapter_files = Dir.glob(File.join(base, "examples/*.rb"))
8181
adapter_missing = {}
8282
adapter_files.each do |path|
83-
source = File.read(path)
83+
source = File.read(path, encoding: Encoding::UTF_8)
8484
if (m = source.match(/config\.missing_features\s*=\s*\[(.*?)\]/m))
8585
symbols = m[1].scan(/:(\w+)/).flatten.map(&:to_sym)
8686
adapter_missing[File.basename(path)] = symbols.to_set

lib/liquid/spec/cli/bench.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ def exec_adapter(cmd)
327327
# without executing it. Returns array of flags like ["--yjit"].
328328
def scan_rubyopt(adapter_path)
329329
return [] unless File.exist?(adapter_path)
330-
content = File.read(adapter_path)
330+
content = File.read(adapter_path, encoding: Encoding::UTF_8)
331331
flags = []
332332
content.scan(/LiquidSpec\.rubyopt\s+["']([^"']+)["']/) do |match|
333333
flags.concat(match[0].split)

lib/liquid/spec/cli/docs.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ def show_doc(name)
7171
exit(1)
7272
end
7373

74-
content = File.read(doc_file)
74+
content = File.read(doc_file, encoding: Encoding::UTF_8)
7575

7676
# Strip frontmatter for display
7777
if content.start_with?("---")
@@ -105,7 +105,7 @@ def load_all_docs
105105
end
106106

107107
def load_doc_metadata(file)
108-
content = File.read(file)
108+
content = File.read(file, encoding: Encoding::UTF_8)
109109
name = File.basename(file, ".md")
110110

111111
# Parse YAML frontmatter if present

lib/liquid/spec/cli/eval.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -483,7 +483,7 @@ def load_spec_file(options)
483483
exit(1)
484484
end
485485

486-
load_spec_from_string(File.read(spec_file), options)
486+
load_spec_from_string(File.read(spec_file, encoding: Encoding::UTF_8), options)
487487
end
488488

489489
def load_spec_from_string(yaml_content, options)
@@ -558,7 +558,7 @@ def append_to_daily_file(spec_data, _has_difference)
558558

559559
existing_specs = []
560560
if File.exist?(daily_file) && File.size?(daily_file).to_i > 0
561-
existing_specs = Liquid::Spec.safe_yaml_load(File.read(daily_file)) || []
561+
existing_specs = Liquid::Spec.safe_yaml_load(File.read(daily_file, encoding: Encoding::UTF_8)) || []
562562
existing_specs = [] unless existing_specs.is_a?(Array)
563563
end
564564

lib/liquid/spec/cli/features.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ def self.count_specs_by_feature
189189

190190
Dir.glob(File.join(spec_root, "**/*.yml")).each do |file|
191191
begin
192-
content = File.read(file)
192+
content = File.read(file, encoding: Encoding::UTF_8)
193193
data = YAML.safe_load(content, permitted_classes: [Symbol, Range], aliases: true)
194194
next unless data
195195

@@ -222,7 +222,7 @@ def self.count_total_specs
222222

223223
Dir.glob(File.join(spec_root, "**/*.yml")).each do |file|
224224
begin
225-
content = File.read(file)
225+
content = File.read(file, encoding: Encoding::UTF_8)
226226
data = YAML.safe_load(content, permitted_classes: [Symbol, Range], aliases: true)
227227
next unless data
228228

lib/liquid/spec/cli/report.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ def load_benchmark_data(reports_dir, options)
141141
adapter_from_filename = File.basename(path, ".jsonl")
142142
next if options[:adapters].any? && !options[:adapters].include?(adapter_from_filename)
143143

144-
File.foreach(path) do |line|
144+
File.foreach(path, encoding: Encoding::UTF_8) do |line|
145145
next if line.strip.empty?
146146

147147
begin

lib/liquid/spec/cli/runner.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ def initialize
3434
def load_file(path)
3535
return unless path && File.exist?(path)
3636

37-
File.readlines(path).each do |line|
37+
File.readlines(path, encoding: Encoding::UTF_8).each do |line|
3838
add(line.strip)
3939
end
4040
end

lib/liquid/spec/cli/runs.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ def make_adapter(path, local:)
200200
end
201201

202202
def adapter_transport(path)
203-
source = File.read(path)
203+
source = File.read(path, encoding: Encoding::UTF_8)
204204
if source.match?(/liquid\/spec\/json_rpc\/adapter|JsonRpc::Adapter/)
205205
:json_rpc
206206
else

lib/liquid/spec/spec_loader.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ def load_suite(suite)
128128
# Load specs from a single YAML file
129129
# Returns array of LazySpec objects
130130
def load_yaml_file(path, suite: nil)
131-
content = File.read(path)
131+
content = File.read(path, encoding: Encoding::UTF_8)
132132
specs = []
133133

134134
# Fail fast if file contains dangerous !ruby/ tags (e.g. !ruby/object)
@@ -334,20 +334,20 @@ def load_directory_spec(dir, suite: nil)
334334
template_file = File.join(dir, "template.liquid")
335335
return unless File.exist?(template_file)
336336

337-
template = File.read(template_file)
337+
template = File.read(template_file, encoding: Encoding::UTF_8)
338338
name = File.basename(dir)
339339

340340
# Load environment
341341
env_file = File.join(dir, "environment.yml")
342342
raw_environment = if File.exist?(env_file)
343-
safe_load_with_permitted_classes(File.read(env_file)) || {}
343+
safe_load_with_permitted_classes(File.read(env_file, encoding: Encoding::UTF_8)) || {}
344344
else
345345
{}
346346
end
347347

348348
# Load expected output
349349
expected_file = File.join(dir, "expected.html")
350-
expected = File.exist?(expected_file) ? File.read(expected_file) : nil
350+
expected = File.exist?(expected_file) ? File.read(expected_file, encoding: Encoding::UTF_8) : nil
351351

352352
minimum_complexity = suite&.minimum_complexity || 1000
353353

@@ -427,7 +427,7 @@ def load_data_files(data_files, base_dir)
427427
unless File.exist?(file_path)
428428
raise "Data file not found: #{file_path} (referenced from spec in #{base_dir})"
429429
end
430-
file_data = safe_load_with_permitted_classes(File.read(file_path))
430+
file_data = safe_load_with_permitted_classes(File.read(file_path, encoding: Encoding::UTF_8))
431431
next unless file_data.is_a?(Hash)
432432

433433
merged = deep_merge_hashes(merged, file_data)

lib/liquid/spec/suite.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ def reset!
8888
def load_config
8989
suite_file = File.join(@path, SUITE_FILE)
9090
if File.exist?(suite_file)
91-
YAML.safe_load(File.read(suite_file), permitted_classes: [Symbol]) || {}
91+
YAML.safe_load(File.read(suite_file, encoding: Encoding::UTF_8), permitted_classes: [Symbol]) || {}
9292
else
9393
{}
9494
end

0 commit comments

Comments
 (0)