From 568afac4e41e7ec2ac95efe4f2514939f266b194 Mon Sep 17 00:00:00 2001 From: schneems Date: Wed, 13 Feb 2019 12:19:44 -0600 Subject: [PATCH] Ignore invalid byte encodings when detecting rails config Previously if a customer had an invalid byte sequence emitted during boot up, it would raise an error: ``` invalid byte sequence in UTF-8 ``` Which would prevent configuration detection from functioning correctly. When detecting rails configuration, we know that the input we are trying to detect for success will be UTF-8. As a result, we can ignore any other encoded characters. This PR prevents an invalid byte sequence from blocking rails configuration detection. Reference internal support ticket number: 681812 Here's a blog post on invalid byte sequences if you're interested https://thoughtbot.com/blog/fight-back-utf-8-invalid-byte-sequences. --- CHANGELOG.md | 2 ++ lib/language_pack/shell_helpers.rb | 2 +- spec/helpers/rails_runner_spec.rb | 9 +++++++++ 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d44de05cb..b481f47a4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,8 @@ ## Master +* Ignore invalid byte encodings when detecting rails config (https://github.com/heroku/heroku-buildpack-ruby/pull/854) + ## v199 (2/19/2019) * Add support for arbitrary Bundler major versions, most notably bundler 2 (https://github.com/heroku/heroku-buildpack-ruby/pull/850) diff --git a/lib/language_pack/shell_helpers.rb b/lib/language_pack/shell_helpers.rb index c7226a3fd..1e2401731 100644 --- a/lib/language_pack/shell_helpers.rb +++ b/lib/language_pack/shell_helpers.rb @@ -177,7 +177,7 @@ def initialize(command, options = {}) def output raise "no file name given" if @file.nil? exec_once - @file.read + @file.read.encode('UTF-8', invalid: :replace) end def timeout? diff --git a/spec/helpers/rails_runner_spec.rb b/spec/helpers/rails_runner_spec.rb index 7bae1c922..db123b0e0 100644 --- a/spec/helpers/rails_runner_spec.rb +++ b/spec/helpers/rails_runner_spec.rb @@ -78,6 +78,15 @@ def rails_runner.called; @called; end expect(!!local_storage.success?).to eq(true) end + it "does not fail when there is an invalid byte sequence" do + mock_rails_runner('puts "hi \255"') + + rails_runner = LanguagePack::Helpers::RailsRunner.new + local_storage = rails_runner.detect("active_storage.service") + + expect(local_storage.success?).to be_truthy + end + def time_it start = Time.now yield