Skip to content

Commit 9f92c8a

Browse files
committed
Force UTF-8 on discovered OpenBSD sqlports filename to avoid ASCII-8BIT transliterate error
1 parent 720082b commit 9f92c8a

2 files changed

Lines changed: 24 additions & 1 deletion

File tree

app/models/ecosystem/openbsd.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,7 @@ def resolved_sqlports_tgz_filename
369369
def discover_sqlports_tgz_filename
370370
body = get_raw("#{packages_base_url}/")
371371
matches = body.to_s.scan(/href="(sqlports-[\d.]+\.tgz)"/i).flatten
372-
matches.max_by { |match| Gem::Version.new(match[/sqlports-([\d.]+)\.tgz/i, 1]) }
372+
matches.max_by { |match| Gem::Version.new(match[/sqlports-([\d.]+)\.tgz/i, 1]) }&.force_encoding(Encoding::UTF_8)
373373
rescue StandardError => e
374374
Rails.logger.warn("Unable to discover OpenBSD sqlports bundle: #{e.message}")
375375
nil

test/models/ecosystem/openbsd_test.rb

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,4 +119,27 @@ def @ecosystem.download_and_cache(url, *_args, **_kwargs)
119119

120120
assert_equal "sqlports-7.10.tgz", @ecosystem.discover_sqlports_tgz_filename
121121
end
122+
123+
test "load_synced_ports handles binary-encoded discovered sqlports filename" do
124+
registry = Registry.new(
125+
name: "openbsd-7.9-amd64",
126+
url: "https://cdn.openbsd.org/pub/OpenBSD/7.9/packages/amd64",
127+
ecosystem: "openbsd",
128+
metadata: { "arch" => "amd64" }
129+
)
130+
ecosystem = Ecosystem::Openbsd.new(registry)
131+
132+
def ecosystem.download_and_cache(url, *_args, **_kwargs)
133+
fixtures = Rails.root.join("test/fixtures/files/openbsd")
134+
return fixtures.join("index.txt") if url.end_with?("/index.txt")
135+
return fixtures.join("sqlports-7.54.tgz") if url.end_with?("/sqlports-7.54.tgz")
136+
137+
nil
138+
end
139+
140+
body = (+'<a href="sqlports-7.54.tgz">x</a>').force_encoding(Encoding::ASCII_8BIT)
141+
ecosystem.stubs(:get_raw).returns(body)
142+
143+
assert_includes ecosystem.all_package_names, "devel/git"
144+
end
122145
end

0 commit comments

Comments
 (0)