From b632123d6b28c60c7753df1e28a7ede465df16b9 Mon Sep 17 00:00:00 2001 From: Colin Dean Date: Sun, 9 Jan 2022 21:12:52 -0500 Subject: [PATCH] Force UTF-8 encoding of lsb_release output MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit It's possible that the output may be encoded ASCII-8BIT, which cannot be automatically encoded to UTF-8 by Ruby's JSON library. In this particular case, elementaryOS 6.1 returns `Jólnir` as a part of the lsb_release Description field. Ruby's IO.popen would return this whole output in ASCII-8BIT. When this description field was passed to homebrew-bundle to be written in a JSON lockfile, Ruby throws an exception because it could not automatically reencode from ASCII-8BIT to UTF-8. This may actually affect other output of the calls to the underlying `Utils.popen_read` but this may be the first thing to trigger it since JSON requires UTF-8 output and nothing else using that function may require UTF-8. Fixes #12689 12689 Fixes Homebrew/homebrew-bundle#1043 --- Library/Homebrew/os/linux.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Library/Homebrew/os/linux.rb b/Library/Homebrew/os/linux.rb index 3fab729ad7..6c029ef8be 100644 --- a/Library/Homebrew/os/linux.rb +++ b/Library/Homebrew/os/linux.rb @@ -12,7 +12,7 @@ module OS def os_version if which("lsb_release") lsb_info = Utils.popen_read("lsb_release", "-a") - description = lsb_info[/^Description:\s*(.*)$/, 1] + description = lsb_info[/^Description:\s*(.*)$/, 1].force_encoding("UTF-8") codename = lsb_info[/^Codename:\s*(.*)$/, 1] if codename.blank? || (codename == "n/a") description