diff options
author | Siri Hansen <[email protected]> | 2013-01-15 10:48:04 +0100 |
---|---|---|
committer | Siri Hansen <[email protected]> | 2013-01-25 15:55:40 +0100 |
commit | 1f3ce8d2b9c07bee672efec9d6e3512633ffcf23 (patch) | |
tree | 2098fbde396dd47c635340737882e62cc9963300 /erts | |
parent | ed2be3f6913559b8d9ffd65609b7a2ca32367c05 (diff) | |
download | otp-1f3ce8d2b9c07bee672efec9d6e3512633ffcf23.tar.gz otp-1f3ce8d2b9c07bee672efec9d6e3512633ffcf23.tar.bz2 otp-1f3ce8d2b9c07bee672efec9d6e3512633ffcf23.zip |
Make arguments given with -s option to erl aware of file name encoding
OTP-10702
Arguments to functions started with the -s option to erl were
converted to atoms with list_to_atom(binary_to_list(Bin)) and thus
were always seen as latin1 encoded.
For other arguments to erl the conversion (to string) would take into
account the file name translation mode (set with +fnl, +fnu or +fna
switch to erl) and try to convert using
unicode:characters_to_list/2. The reason behind this is that it must
be possible to give paths and filenames on the command line and get
the expected encoding.
With the same reasoning, this commit changes the behaviour for
arguments to functions started with the -s option to also take
into account the file name translation mode. The arguments are now
converted to atoms by
list_to_atom(unicode:characters_to_list(Bin,file:native_name_encoding())
Diffstat (limited to 'erts')
-rw-r--r-- | erts/preloaded/src/init.erl | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/erts/preloaded/src/init.erl b/erts/preloaded/src/init.erl index 1d1087c7f2..61d8df2428 100644 --- a/erts/preloaded/src/init.erl +++ b/erts/preloaded/src/init.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 1996-2012. All Rights Reserved. +%% Copyright Ericsson AB 1996-2013. All Rights Reserved. %% %% The contents of this file are subject to the Erlang Public License, %% Version 1.1, (the "License"); you may not use this file except in @@ -184,12 +184,16 @@ prepare_run_args({run, [M,F|Args]}) -> [b2a(M), b2a(F) | bs2ss(Args)]. b2a(Bin) when is_binary(Bin) -> - list_to_atom(binary_to_list(Bin)); + list_to_atom(b2s(Bin)); b2a(A) when is_atom(A) -> A. b2s(Bin) when is_binary(Bin) -> - binary_to_list(Bin); + try + unicode:characters_to_list(Bin,file:native_name_encoding()) + catch + _:_ -> binary_to_list(Bin) + end; b2s(L) when is_list(L) -> L. @@ -1260,11 +1264,7 @@ get_arguments([]) -> []. to_strings([H|T]) when is_atom(H) -> [atom_to_list(H)|to_strings(T)]; -to_strings([H|T]) when is_binary(H) -> [try - unicode:characters_to_list(H,file:native_name_encoding()) - catch - _:_ -> binary_to_list(H) - end|to_strings(T)]; +to_strings([H|T]) when is_binary(H) -> [b2s(H)|to_strings(T)]; to_strings([]) -> []. get_argument(Arg,Flags) -> |