Skip to content

Commit 3e1f56e

Browse files
authored
Fix unicode crash (#5)
1 parent b6198b2 commit 3e1f56e

File tree

3 files changed

+30
-6
lines changed

3 files changed

+30
-6
lines changed

src/rebar3_sheldon_ast.erl

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,10 +108,13 @@ collect_comments([{Line, _Column, _Indent, Comments} | T], AccC, RegEx) ->
108108

109109
-spec re_replace(string() | binary()) -> string().
110110
re_replace(Str) ->
111-
re:replace(Str, "%|@", "", [global, {return, list}]).
111+
re:replace(
112+
unicode:characters_to_binary(Str), "%|@", "", [global, {return, list}]).
112113

113114
-spec is_ignore(string(), string() | undefined) -> boolean().
114115
is_ignore(_, undefined) ->
115116
false;
116117
is_ignore(String, RegEx) ->
117-
re:run(String, RegEx) /= nomatch.
118+
re:run(
119+
unicode:characters_to_binary(String), RegEx)
120+
/= nomatch.

test/rebar3_sheldon_SUITE.erl

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@
66
-include_lib("stdlib/include/assert.hrl"). % Assertion macros for convenience
77

88
-export([all/0, groups/0, init_per_testcase/2, end_per_testcase/2]).
9-
-export([test_app/1, no_good_files/1, emits_warnings/1, ignore_regex/1]).
9+
-export([test_app/1, no_good_files/1, emits_warnings/1, ignore_regex/1, unicode/1]).
1010

1111
-spec all() -> [ct_suite:ct_test_def(), ...].
1212
all() ->
13-
[test_app, no_good_files, emits_warnings, ignore_regex].
13+
[test_app, no_good_files, emits_warnings, ignore_regex, unicode].
1414

1515
-spec groups() -> [ct_suite:ct_group_def(), ...].
1616
groups() ->
@@ -66,9 +66,18 @@ ignore_regex(_Config) ->
6666
IgnoreRegEx = {ignore_regex, "[_@./#&+-=*]"},
6767
State2 = rebar_state:set(State1, spellcheck, [Files, IgnoreRegEx]),
6868
{Res, _} = spellcheck(State2),
69-
%% Check warning message
7069
?assertEqual(ok, Res).
7170

71+
-spec unicode(ct_suite:ct_config()) -> ok | no_return().
72+
unicode(_Config) ->
73+
ok = file:set_cwd("../../../../test/test_app"),
74+
{ok, State1} = init(),
75+
Files = {files, ["src/test_unicode.erl"]},
76+
State2 = rebar_state:set(State1, spellcheck, [Files]),
77+
{error, ErrorMsg} = spellcheck(State2),
78+
%% Check warning message
79+
?assertEqual(ErrorMsg, string:find(ErrorMsg, "spellcheck detect warning emits:")).
80+
7281
%% =============================================================================
7382
%% Helpers
7483
%% =============================================================================
@@ -96,6 +105,10 @@ init_test_app() ->
96105
"src/*.hrl"]},
97106
IgnoredFiles =
98107
{ignore,
99-
["src/*_ignore.erl", "src/*_broken.erl", "src/*_warning.erl", "src/*_ignore_regex.erl"]},
108+
["src/*_ignore.erl",
109+
"src/*_broken.erl",
110+
"src/*_warning.erl",
111+
"src/*_ignore_regex.erl",
112+
"src/*_unicode.erl"]},
100113
IgnoreRegEx = {ignore_regex, "[_@./#&+-=*]"},
101114
rebar_state:set(State1, spellcheck, [Files, IgnoredFiles, IgnoreRegEx]).

test/test_app/src/test_unicode.erl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
-module(test_unicode).
2+
3+
-export([hello/1]).
4+
5+
%% ’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’
6+
7+
hello() ->
8+
"Привет Мир!".

0 commit comments

Comments
 (0)