Skip to content

Commit ae24cad

Browse files
author
José Valim
committed
Limit the allowed sigils
1 parent a8eab99 commit ae24cad

File tree

4 files changed

+6
-2
lines changed

4 files changed

+6
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
* Backwards incompatible changes
2121
* [Dict] Implementations of `equal?/2` and `merge/2` in `HashDict` and `ListDict` are no longer polymorphic. To get polymorphism, use the functions in `Dict` instead
2222
* [Kernel] Remove `**` from the list of allowed operators
23+
* [Kernel] Limit sigils delimiters to one of the following: `<>`, `{}`, `[]`, `()`, `||`, `//`, `"` and `'`
2324
* [Range] `Range` is no longer a record, instead use `first .. last` if you need pattern matching
2425
* [Set] Implementations of `difference/2`, `disjoint?/2`, `equal?/2`, `intersection/2`, `subset?/2` and `union/2` in `HashSet` are no longer polymorphic. To get polymorphism, use the functions in `Set` instead
2526

lib/elixir/include/elixir.hrl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,8 @@
8080
-define(is_atom(S), ?is_identifier(S) orelse (S == $@)).
8181

8282
-define(is_identifier(S), ?is_digit(S) orelse ?is_upcase(S) orelse ?is_downcase(S) orelse (S == $_)).
83-
-define(is_terminator(S), (S == $?) orelse (S == $!) orelse (S == $:)).
83+
-define(is_sigil(S), (S == $/) orelse (S == $<) orelse (S == $") orelse (S == $') orelse
84+
(S == $[) orelse (S == $() orelse (S == ${) orelse (S == $|)).
8485

8586
%% Quotes
8687
-define(is_quote(S), S == $" orelse S == $').

lib/elixir/src/elixir_tokenizer.erl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ tokenize([$%,S,H,H,H|T] = Original, Line, Scope, Tokens) when ?is_quote(H), ?is_
145145
{ error, Reason, Original, Tokens }
146146
end;
147147

148-
tokenize([$%,S,H|T] = Original, Line, Scope, Tokens) when not(?is_identifier(H)), not(?is_terminator(H)), ?is_upcase(S) orelse ?is_downcase(S) ->
148+
tokenize([$%,S,H|T] = Original, Line, Scope, Tokens) when ?is_sigil(H), ?is_upcase(S) orelse ?is_downcase(S) ->
149149
case elixir_interpolation:extract(Line, Scope, ?is_downcase(S), T, sigil_terminator(H)) of
150150
{ NewLine, Parts, Rest } ->
151151
{ Final, Modifiers } = collect_modifiers(Rest, []),

lib/elixir/test/elixir/kernel/sigils_test.exs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ defmodule Kernel.SigilsTest do
2121
assert %S{foo} == "foo"
2222
assert %S'foo' == "foo"
2323
assert %S"foo" == "foo"
24+
assert %S<foo> == "foo"
25+
assert %S/foo/ == "foo"
2426
assert %S|foo| == "foo"
2527
assert %S(f#{o}o) == "f\#{o}o"
2628
assert %S(f\no) == "f\\no"

0 commit comments

Comments
 (0)