diff --git a/lib/elixir/src/elixir_interpolation.erl b/lib/elixir/src/elixir_interpolation.erl index 0565c845556..58ee4567b38 100644 --- a/lib/elixir/src/elixir_interpolation.erl +++ b/lib/elixir/src/elixir_interpolation.erl @@ -80,6 +80,15 @@ extract([$\\ | Rest], Buffer, Output, Line, Column, Scope, Interpol, Last) -> %% Catch all clause +extract([Char | _Rest], _Buffer, _Output, Line, Column, _Scope, _Interpol, _Last) + when ?break(Char) -> + Token = io_lib:format("\\u~4.16.0B", [Char]), + Pos = io_lib:format(". If you want to use such character, use it in its escaped ~ts form instead", [Token]), + {error, {?LOC(Line, Column), + {"invalid line break character in string: ", + Pos}, + Token}}; + extract([Char1, Char2 | Rest], Buffer, Output, Line, Column, Scope, Interpol, Last) when Char1 =< 255, Char2 =< 255 -> extract([Char2 | Rest], [Char1 | Buffer], Output, Line, Column + 1, Scope, Interpol, Last); diff --git a/lib/elixir/test/elixir/kernel/parser_test.exs b/lib/elixir/test/elixir/kernel/parser_test.exs index 8502a5a0b4d..de906fd19e0 100644 --- a/lib/elixir/test/elixir/kernel/parser_test.exs +++ b/lib/elixir/test/elixir/kernel/parser_test.exs @@ -1131,6 +1131,30 @@ defmodule Kernel.ParserTest do ], ~c"\"this is a \\\u2028\"" ) + + assert_syntax_error( + [ + "nofile:1:12:", + "invalid line break character in string: \\u000B. If you want to use such character, use it in its escaped \\u000B form instead" + ], + :erlang.list_to_binary([34] ++ ~c"this is a " ++ [11, 34]) + ) + + assert_syntax_error( + [ + "nofile:1:12:", + "invalid line break character in string: \\u000C. If you want to use such character, use it in its escaped \\u000C form instead" + ], + :erlang.list_to_binary([34] ++ ~c"this is a " ++ [12, 34]) + ) + + assert_syntax_error( + [ + "nofile:1:12:", + "invalid line break character in string: \\u0085. If you want to use such character, use it in its escaped \\u0085 form instead" + ], + <<34, "this is a ", 194, 133, 34>> + ) end test "reserved tokens" do