Skip to content

Ensure errors.css is interpreted as UTF-8 encoding

Stan Hu requested to merge sh-force-errors-css-utf-8 into master

What does this MR do and why?

Since gitlab-foss!19096 (merged), we've inlined the errors.css by directly including the Sprockets assets into the HAML. This worked fine as long as the CSS file remained as a plain ASCII file. However, the switch to the new CSS pipeline with !144479 (merged) appears to have introduced a single UTF-8 character. Since Sprockets loads the asset via File.binread (https://github.com/rails/sprockets/blob/d1dcf7075c468522e1cb6f93ae547d8d7fdcfbcb/lib/sprockets/asset.rb#L99), the contents of this UTF-8 file is forced as ASCII-8BIT. When this ASCII-8BIT string is combined with other UTF-8 characters, such as Chinese characters, the encoding fails with a 500 error: incompatible character encodings: ASCII-8BIT and UTF-8 (Encoding::CompatibilityError).

To work around this issue, we force the encoding to UTF-8 to ensure the error page can render.

Relates to gitlab-com/gl-infra/production#17627 (closed)

Edited by Stan Hu

Merge request reports