Skip to content

Commit 127a262

Browse files
committed
Fix issue with Kernel#` when invalid UTF-8 bytes are given
1 parent 65215e7 commit 127a262

File tree

4 files changed

+8
-2
lines changed

4 files changed

+8
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ Bug fixes:
99
* Fix error message when the method name is not a Symbol or String for `Kernel#respond_to?` (#2132, @ssnickolay)
1010
* Fixed setting of special variables in enumerators and enumerables (#1484).
1111
* Fixed return value of `Enumerable#count` and `Enumerable#uniq` with multiple yielded arguments (#2145, @LillianZ).
12+
* Fixed issue with ``Kernel#` `` when invalid UTF-8 given (#2118).
1213

1314
Compatibility:
1415

spec/ruby/core/kernel/backtick_spec.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@
3535
-> { `nonexistent_command` }.should raise_error(Errno::ENOENT)
3636
end
3737

38+
it "handles invalid UTF-8 bytes in command" do
39+
`echo "testing\xC2 a non UTF-8 string"`.should == "testing\xC2 a non UTF-8 string\n"
40+
end
41+
3842
platform_is_not :windows do
3943
it "sets $? to the exit status of the executed sub-process" do
4044
ip = 'world'

spec/tags/core/kernel/backtick_tags.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ slow:Kernel#` produces a String in the default external encoding
44
slow:Kernel#` raises an Errno::ENOENT if the command is not executable
55
slow:Kernel#` sets $? to the exit status of the executed sub-process
66
slow:Kernel.` tries to convert the given argument to String using #to_str
7+
slow:Kernel#` handles invalid UTF-8 bytes in command

src/main/ruby/truffleruby/core/truffle/process_operations.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ module ProcessOperations
8989
]
9090
# A simplified version of Regexp.new("[#{SHELL_META_CHARS.map { |c| Regexp.escape(c) }.join}]")
9191
# to avoid running too much code during initialization
92-
SHELL_META_CHAR_PATTERN = /[*?{}\[\]<>()~&|\\$;'`"\n#=%]/
92+
SHELL_META_CHAR_PATTERN = /[*?{}\[\]<>()~&|\\$;'`"\n#=%]/n
9393

9494
def self.exec(*args)
9595
exe = Execute.new
@@ -543,7 +543,7 @@ def exec
543543
end
544544

545545
def should_use_shell?(command)
546-
command.match?(SHELL_META_CHAR_PATTERN)
546+
command.b.match?(SHELL_META_CHAR_PATTERN)
547547
end
548548

549549
def should_search_path?(command)

0 commit comments

Comments
 (0)