47
47
import java .nio .channels .Channel ;
48
48
import java .nio .channels .Channels ;
49
49
import java .nio .channels .WritableByteChannel ;
50
- import java .nio .charset .StandardCharsets ;
51
50
import java .util .ArrayList ;
52
51
import java .util .HashMap ;
53
52
import java .util .List ;
@@ -164,10 +163,10 @@ private synchronized int forkExec(PList args, PList execList, @SuppressWarnings(
164
163
if (keyValue instanceof PBytes ) {
165
164
// NOTE: passing 'null' frame means we took care of the global state in the
166
165
// callers
167
- byte [] bytes = checkNullBytes (toBytes .execute (null , keyValue ));
168
- String [] string = new String ( bytes , StandardCharsets . US_ASCII ) .split ("=" , 2 );
169
- if (string .length == 2 ) {
170
- envMap .put (string [0 ], string [1 ]);
166
+ String str = checkNullBytesAndEncode (toBytes .execute (null , keyValue ));
167
+ String [] strings = str .split ("=" , 2 );
168
+ if (strings .length == 2 ) {
169
+ envMap .put (strings [0 ], strings [1 ]);
171
170
}
172
171
}
173
172
}
@@ -199,8 +198,7 @@ private synchronized int forkExec(PList args, PList execList, @SuppressWarnings(
199
198
if (!(item instanceof PBytes )) {
200
199
throw raise (PythonBuiltinClassType .TypeError , ErrorMessages .EXPECTED_BYTES_P_FOUND , item );
201
200
}
202
- byte [] bytes = checkNullBytes (toBytes .execute (null , item ));
203
- String path = new String (bytes , StandardCharsets .US_ASCII );
201
+ String path = checkNullBytesAndEncode (toBytes .execute (null , item ));
204
202
int executableListLen = 0 ;
205
203
if (path .equals (context .getOption (PythonOptions .Executable ))) {
206
204
// In case someone passed to us sys.executable that happens to be java command
@@ -222,8 +220,8 @@ private synchronized int forkExec(PList args, PList execList, @SuppressWarnings(
222
220
firstError = ex ;
223
221
}
224
222
}
225
- for (int j = 0 ; j < executableListLen - 1 ; j ++) {
226
- argStrings .remove (j + 1 );
223
+ for (int j = 1 ; j < executableListLen ; j ++) {
224
+ argStrings .remove (1 );
227
225
}
228
226
}
229
227
assert firstError != null ;
@@ -291,13 +289,17 @@ private int exec(ArrayList<String> argStrings, File cwd, Map<String, String> env
291
289
return resources .registerChild (process );
292
290
}
293
291
294
- private byte [] checkNullBytes (byte [] bytes ) {
292
+ private String checkNullBytesAndEncode (byte [] bytes ) {
295
293
for (byte b : bytes ) {
296
294
if (b == 0 ) {
297
295
throw raise (PythonBuiltinClassType .ValueError , ErrorMessages .EMBEDDED_NULL_BYTE );
298
296
}
299
297
}
300
- return bytes ;
298
+ // Note: we use intentionally the default encoding for the bytes. We're most likely
299
+ // getting bytes that the Python wrapper encoded from strings passed to it by the user
300
+ // and we should support non-ascii characters supported by the current FS. See
301
+ // test_warnings.test_nonascii
302
+ return new String (bytes );
301
303
}
302
304
303
305
@ TruffleBoundary (allowInlining = true )
0 commit comments