Skip to content
This repository has been archived by the owner on Jan 3, 2024. It is now read-only.

Commit

Permalink
Ignore invalid byte encodings when detecting rails config
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
schneems committed Feb 19, 2019
1 parent 1962b06 commit 568afac
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
2 changes: 2 additions & 0 deletions 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)
Expand Down
2 changes: 1 addition & 1 deletion lib/language_pack/shell_helpers.rb
Expand Up @@ -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?
Expand Down
9 changes: 9 additions & 0 deletions spec/helpers/rails_runner_spec.rb
Expand Up @@ -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
Expand Down

0 comments on commit 568afac

Please sign in to comment.