Permalink
Browse files

Fix EM.system when unicode characters used (eventmachine#322).

  • Loading branch information...
1 parent c12c20b commit dd57cefb952c2978250a6795313ff3fb56aeccba @ibc committed Apr 2, 2013
Showing with 51 additions and 3 deletions.
  1. +2 −1 README.md
  2. +1 −1 lib/em/processes.rb
  3. +6 −1 lib/eventmachine.rb
  4. +42 −0 tests/test_system.rb
View
@@ -51,8 +51,9 @@ The list of additions and improvements will grow over time. Currently the follow
### Version 1.1.5
-* Fix bug when the system time is changed to earlier time (which made EM to eat up the CPu cycle): [commit in EM](https://github.com/eventmachine/eventmachine/commit/1427a2c80c401d841194132a9af15baefd68b5ae).
+* Fix bug when the system time is changed to earlier time (which made EM to eat up the CPU cycle): [commit in EM](https://github.com/eventmachine/eventmachine/commit/1427a2c80c401d841194132a9af15baefd68b5ae).
* Fix crash on attach/detach in the same tick ([pietern](https://github.com/eventmachine/eventmachine/pull/427)).
+* Fix `EM.system` when unicode characters used ([funny-falcon](https://github.com/eventmachine/eventmachine/pull/322)).
### Version 1.1.4 and below
View
@@ -114,7 +114,7 @@ def EventMachine::system cmd, *args, &cb
init = args.pop if args.last.is_a? Proc
# merge remaining arguments into the command
- cmd = ([cmd] + args.map{|a|a.to_s.dump}).join(' ')
+ cmd = [cmd, *args] if args.any?
EM.get_subprocess_pid(EM.popen(cmd, SystemCmd, cb) do |c|
init[c] if init
View
@@ -1172,7 +1172,12 @@ def self.popen cmd, handler=nil, *args
# Perhaps misnamed since the underlying function uses socketpair and is full-duplex.
klass = klass_from_handler(Connection, handler, *args)
- w = Shellwords::shellwords( cmd )
+ w = case cmd
+ when Array
+ cmd
+ when String
+ Shellwords::shellwords( cmd )
+ end
w.unshift( w.first ) if w.first
s = invoke_popen( w )
c = klass.new s, *args
View
@@ -0,0 +1,42 @@
+# coding: utf-8
+require 'em_test_helper'
+
+class TestSystem < Test::Unit::TestCase
+ def setup
+ @filename = File.expand_path("../я манал dump.txt", __FILE__)
+ @test_data = 'a' * 100
+ File.open(@filename, 'w'){|f| f.write(@test_data)}
+ end
+
+ def test_system
+ result = nil
+ status = nil
+ EM.run {
+ EM.system('cat', @filename){|out, state|
+ result = out
+ status = state.exitstatus
+ EM.stop
+ }
+ }
+ assert_equal(0, status)
+ assert_equal(@test_data, result)
+ end
+
+ def test_system_with_string
+ result = nil
+ status = nil
+ EM.run {
+ EM.system("cat '#@filename'"){|out, state|
+ result = out
+ status = state.exitstatus
+ EM.stop
+ }
+ }
+ assert_equal(0, status)
+ assert_equal(@test_data, result)
+ end
+
+ def teardown
+ File.unlink(@filename)
+ end
+end

0 comments on commit dd57cef

Please sign in to comment.