From 298ff42f5f80a603306a007540d1c75a013bcf81 Mon Sep 17 00:00:00 2001 From: Hans Bolinder Date: Mon, 2 Sep 2013 15:07:52 +0200 Subject: Fix a Unicode filename bug affecting Leex and Yecc A bug where Unicode filenames combined with Latin-1 encoding could crash Yecc and Leex has been fixed. --- lib/parsetools/src/leex.erl | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'lib/parsetools/src/leex.erl') diff --git a/lib/parsetools/src/leex.erl b/lib/parsetools/src/leex.erl index e531b78a5b..7039aea1ae 100644 --- a/lib/parsetools/src/leex.erl +++ b/lib/parsetools/src/leex.erl @@ -1645,10 +1645,14 @@ output_encoding_comment(File, #leex{encoding = Encoding}) -> output_file_directive(File, Filename, Line) -> io:fwrite(File, <<"-file(~ts, ~w).\n">>, - [format_filename(Filename), Line]). + [format_filename(Filename, File), Line]). -format_filename(Filename) -> - io_lib:write_string(filename:flatten(Filename)). +format_filename(Filename0, File) -> + Filename = filename:flatten(Filename0), + case lists:keyfind(encoding, 1, io:getopts(File)) of + {encoding, unicode} -> io_lib:write_string(Filename); + _ -> io_lib:write_string_as_latin1(Filename) + end. quote($^) -> "\\^"; quote($.) -> "\\."; -- cgit v1.2.3