Skip to content

Commit 55d3aee

Browse files
committed
FIX: Email does not handle non ascii chars correctly
fixes: Oldes/Rebol-issues#2406
1 parent b755c7a commit 55d3aee

File tree

3 files changed

+14
-7
lines changed

3 files changed

+14
-7
lines changed

src/core/l-types.c

+7-7
Original file line numberDiff line numberDiff line change
@@ -705,14 +705,11 @@ bad_hex: Trap0(RE_INVALID_CHARS);
705705
**
706706
***********************************************************************/
707707
{
708-
REBYTE *str;
708+
REBYTE *str = Reset_Buffer(BUF_FORM, len);
709709
REBOOL at = FALSE;
710710
REBUNI n;
711+
REBCNT cnt = len;
711712

712-
VAL_SERIES(value) = Make_Binary(len);
713-
VAL_INDEX(value) = 0;
714-
715-
str = VAL_BIN(value);
716713
for (; len > 0; len--) {
717714
if (*cp == '@') {
718715
if (at) return 0;
@@ -721,14 +718,17 @@ bad_hex: Trap0(RE_INVALID_CHARS);
721718
if (*cp == '%') {
722719
if (len <= 2 || !Scan_Hex2(cp+1, &n, FALSE)) return 0;
723720
*str++ = (REBYTE)n;
724-
cp += 3;
721+
cp += 3;
725722
len -= 2;
723+
cnt -= 2;
726724
}
727725
else *str++ = *cp++;
728726
}
729727
*str = 0;
730728
if (!at) return 0;
731-
VAL_TAIL(value) = (REBCNT)(str - VAL_BIN(value));
729+
730+
VAL_SERIES(value) = Decode_UTF_String(BIN_DATA(BUF_FORM), cnt, 8, FALSE);
731+
VAL_INDEX(value) = 0;
732732
VAL_SET(value, REB_EMAIL);
733733
return cp;
734734
}

src/tests/units/lexer-test.r3

+2
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ Rebol [
2626
--test-- "valid `emails`"
2727
--assert email? load {name@where}
2828
--assert email? load {@name} ;@@ https://github.com/Oldes/Rebol-issues/issues/1962
29+
--assert email? load {a@šiška}
30+
--assert email? load {@%C5%A1}
2931

3032
===end-group===
3133

src/tests/units/mold-test.r3

+5
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,11 @@ Rebol [
317317
--test-- "issue-159"
318318
;@@ https://github.com/Oldes/Rebol-issues/issues/159
319319
--assert "a@b" = mold a@b
320+
--test-- "issue-2406"
321+
;@@ https://github.com/Oldes/Rebol-issues/issues/2406
322+
--assert "a@šiška" = mold a@šiška
323+
--assert "a@š" = mold a@%C5%A1
324+
320325
===end-group===
321326

322327
===start-group=== "mold image!"

0 commit comments

Comments
 (0)