Skip to content

Commit 1c69d12

Browse files
authored
Merge pull request #54 from demarey/53-command-and-arguments-should-be-encoded-with-the-platform-encoding
Fixes #53 command and arguments should be encoded with the platform …
2 parents c6f47b6 + 70ccc96 commit 1c69d12

File tree

18 files changed

+69
-21
lines changed

18 files changed

+69
-21
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
tests - basic
2+
testBasicCommandWithNonAsciiArgument
3+
| command |
4+
5+
self withNonAsciiDirectoryDo: [ :dir |
6+
command := self newCommand
7+
command: '/bin/ls';
8+
arguments: { dir fullName }.
9+
command runAndWait
10+
]
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
tests - shell
2+
testBasicShellCommandWithNonAsciiCharacters
3+
4+
self withNonAsciiDirectoryDo: [ :dir |
5+
(dir / 'ok.txt') ensureCreateFile.
6+
self newCommand
7+
shellCommand: 'ls ', dir fullName;
8+
redirectStdout;
9+
runAndWaitOnExitDo: [ :command :outString |
10+
self assert: (outString includesSubstring: 'ok.txt').
11+
]
12+
]
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
helpers
2+
withNonAsciiDirectoryDo: aBlock
3+
| directory |
4+
directory := FileLocator temp / (self class name , '-éoï-' , UUIDGenerator next asString).
5+
directory ensureCreateDirectory.
6+
[ aBlock cull: directory asFileReference ]
7+
ensure: [ directory ensureDeleteAll ]

repository/OSSubprocess-Tests-Unit.package/OSSVMProcessTest.class/instance/testChangeDir.st

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ testChangeDir
33
| oldDir |
44
oldDir := self systemAccessor getcwd.
55
OSSVMProcess vmProcess
6-
lockCwdWithValue: '/tmp'
6+
lockCwdWithValue: '/tmp'
7+
encoding: #utf8
78
during: [
89
"Grrr in latest OSX /tmp is mapped to /private/tmp..."
910
self assert: ((self systemAccessor getcwd = '/tmp') or: [ self systemAccessor getcwd = '/private/tmp' ]).

repository/OSSubprocess-Tests-Unit.package/OSSVMProcessTest.class/instance/testChangeDirWithNonAsciiCharacters.st

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ testChangeDirWithNonAsciiCharacters
66
newDir ensureCreateDirectory.
77

88
OSSVMProcess vmProcess
9-
lockCwdWithValue: newDir fullName
9+
lockCwdWithValue: newDir fullName
10+
encoding: #utf8
1011
during: [ duringSystemCwd := self systemAccessor getcwd ].
1112
duringSystemCwd := UnicodeNormalizer new toNFC: duringSystemCwd asByteArray utf8Decoded.
1213

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
tests
22
testChangeDirWithNonExistingDir
3-
| oldDir |
3+
| oldDir |
44
oldDir := self systemAccessor getcwd.
5-
[ OSSVMProcess vmProcess lockCwdWithValue: '/tmpWhatever' during: [ ] ]
6-
on: Error do: [ :ex | ex printString includesSubstring: 'does not exist' ].
7-
self assert: self systemAccessor getcwd equals: oldDir
8-
5+
[ OSSVMProcess vmProcess
6+
lockCwdWithValue: '/tmpWhatever'
7+
encoding: #utf8
8+
during: [ ] ]
9+
on: Error
10+
do: [ :ex | self assert: (ex printString includesSubstring: 'does not exist') ].
11+
self assert: self systemAccessor getcwd equals: oldDir
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
settings
22
arguments: anObject
3-
arguments := anObject
3+
arguments := anObject collect: [ :each | (each encodeWith: encoding) asString ]
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
settings
2-
command: anObject
3-
command := anObject
2+
command: aString
3+
command := (aString encodeWith: encoding) asString
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
accessing
2+
defaultEncoding
3+
^ OSEnvironment current defaultEncoding
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
settings
2+
encoding: anEncoder
3+
"Specify the encoder to use to encode/decode Strings given to/retrieved from the process.
4+
Default encoding for Unix-like systems is UTF-8".
5+
" self encoding: #utf8 "
6+
encoding := anEncoder

0 commit comments

Comments
 (0)