File tree 3 files changed +18
-0
lines changed
lib/overcommit/hook_context
spec/overcommit/hook_context
3 files changed +18
-0
lines changed Original file line number Diff line number Diff line change 1
1
# Overcommit Changelog
2
2
3
+ ## master (unreleased)
4
+
5
+ * Fix bug where amending a commit with command line arguments containing
6
+ Unicode characters could cause a crash due to invalid byte sequences
7
+
3
8
## 0.32.0.rc1
4
9
5
10
* Add ` concurrency ` global option allowing you to specify the number of threads
Original file line number Diff line number Diff line change @@ -15,6 +15,13 @@ def amendment?
15
15
cmd = Overcommit ::Utils . parent_command
16
16
amend_pattern = 'commit(\s.*)?\s--amend(\s|$)'
17
17
18
+ # Since the ps command can return invalid byte sequences for commands
19
+ # containing unicode characters, we replace the offending characters,
20
+ # since the pattern we're looking for will consist of ASCII characters
21
+ unless cmd . valid_encoding?
22
+ cmd = cmd . encode ( 'UTF-16be' , invalid : :replace , replace : '?' ) . encode ( 'UTF-8' )
23
+ end
24
+
18
25
return @amendment if
19
26
# True if the command is a commit with the --amend flag
20
27
@amendment = !( /\s #{ amend_pattern } / =~ cmd ) . nil?
Original file line number Diff line number Diff line change 20
20
it { should == true }
21
21
end
22
22
23
+ context 'when the parent command contains invalid byte sequence' do
24
+ let ( :command ) { "git commit --amend -m \xE3 M^AM^B" }
25
+
26
+ it { should == true }
27
+ end
28
+
23
29
context 'when amending a commit using a git alias' do
24
30
around do |example |
25
31
repo do
You can’t perform that action at this time.
0 commit comments