Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/committer/git_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def staged_diff
stdout, stderr, status = Open3.capture3('git diff --staged')
raise Committer::Error, "Failed to get git diff: #{stderr}" unless status.success?

stdout
stdout.dup.force_encoding('UTF-8').scrub
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion spec/committer/commit_generator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
require 'committer/commit_generator'

RSpec.describe Committer::CommitGenerator do
let(:diff) { load_fixture('sample_diff.txt') }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think sample diff is only used here so if you removed it we can delete the file

let(:diff) { load_fixture('utf-8-diff.txt') }
let(:commit_context) { nil }
let(:summary_response) { JSON.parse(load_fixture('claude_response_summary.json')) }
let(:body_response) { JSON.parse(load_fixture('claude_response_with_body.json')) }
Expand Down
23 changes: 23 additions & 0 deletions spec/committer/git_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,29 @@
Committer::GitHelper.staged_diff
end.to raise_error(Committer::Error, 'Failed to get git diff: error message')
end

it 'properly handles UTF-8 characters in diff output' do
utf8_diff = load_fixture('utf-8-diff.txt')
allow(Open3).to receive(:capture3).with('git diff --staged').and_return([utf8_diff, '',
double(success?: true)])
result = Committer::GitHelper.staged_diff
expect(result.encoding.name).to eq('UTF-8')
expect(result.valid_encoding?).to be true
expect(result).to eq(utf8_diff)
end

it 'handles invalid UTF-8 characters in diff output' do
invalid_utf8_diff = load_fixture('invalid-utf8-diff.txt')
# Make sure the test fixture has invalid UTF-8 characters
invalid_utf8_data = invalid_utf8_diff.dup.force_encoding('UTF-8')
expect(invalid_utf8_data.valid_encoding?).to be false

allow(Open3).to receive(:capture3).with('git diff --staged').and_return([invalid_utf8_diff, '',
double(success?: true)])
result = Committer::GitHelper.staged_diff
expect(result.encoding.name).to eq('UTF-8')
expect(result.valid_encoding?).to be true
end
end

describe '.commit' do
Expand Down
7 changes: 7 additions & 0 deletions spec/fixtures/invalid-utf8-diff.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
diff --git a/test.txt b/test.txt
new file mode 100644
index 0000000..ea49386
--- /dev/null
+++ b/test.txt
@@ -0,0 +1 @@
+This is a string with invalid UTF-8 bytes: �( �( �(�(
11 changes: 0 additions & 11 deletions spec/fixtures/sample_diff.txt

This file was deleted.

7 changes: 7 additions & 0 deletions spec/fixtures/utf-8-diff.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
diff --git a/test.txt b/test.txt
new file mode 100644
index 0000000..ea49386
--- /dev/null
+++ b/test.txt
@@ -0,0 +1 @@
+Привіт, світ