Skip to content

Commit

Permalink
Merge pull request #125 from Shopify/at-fix-sigil-encoding
Browse files Browse the repository at this point in the history
Fix encoding issues when writing non-ASCII content
  • Loading branch information
Morriar committed Apr 5, 2022
2 parents 95e184d + 8fa8197 commit 7dc2c69
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/spoom/sorbet/sigils.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def self.change_sigil_in_file(path, new_strictness)
content = File.read(path, encoding: Encoding::ASCII_8BIT)
new_content = update_sigil(content, new_strictness)

File.write(path, new_content)
File.write(path, new_content, encoding: Encoding::ASCII_8BIT)

strictness_in_content(new_content) == new_strictness
end
Expand Down
23 changes: 23 additions & 0 deletions test/spoom/sorbet/sigils_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,29 @@ def test_change_sigil_in_file_with_iso_content
project.destroy
end

def test_change_sigil_in_file_with_default_internal_encoding
project = spoom_project

string = <<~RB
# typed: true
puts "À coûté 10€"
RB

old_encoding = Encoding.default_internal
project.write("file.rb", string.encode("UTF-8"))

begin
Encoding.default_internal = Encoding::UTF_8

Sigils.change_sigil_in_file("#{project.path}/file.rb", "strict")
assert_equal("strict", Sigils.file_strictness("#{project.path}/file.rb"))
ensure
Encoding.default_internal = old_encoding
project.destroy
end
end

def test_change_sigil_in_files_false_to_true
project = spoom_project
project.write("file1.rb", "# typed: false")
Expand Down

0 comments on commit 7dc2c69

Please sign in to comment.