Skip to content

Commit a8b9ac9

Browse files
committed
FIX: MOLD of URL containing unicode chars is invalid
fixes: metaeducation/rebol-issues#2379 (This was actually a lexer error)
1 parent 76c87a9 commit a8b9ac9

File tree

2 files changed

+28
-7
lines changed

2 files changed

+28
-7
lines changed

src/core/l-types.c

+8-7
Original file line numberDiff line numberDiff line change
@@ -742,8 +742,9 @@ bad_hex: Trap0(RE_INVALID_CHARS);
742742
**
743743
***********************************************************************/
744744
{
745-
REBYTE *str;
746745
REBUNI n;
746+
REBYTE *str = Reset_Buffer(BUF_FORM, len);
747+
REBCNT cnt = len;
747748

748749
// !!! Need to check for any possible scheme followed by ':'
749750

@@ -753,22 +754,22 @@ bad_hex: Trap0(RE_INVALID_CHARS);
753754
// if (n >= URL_MAX) return 0;
754755
// if (*str != ':') return 0;
755756

756-
VAL_SERIES(value) = Make_Binary(len);
757-
VAL_INDEX(value) = 0;
758-
759-
str = VAL_BIN(value);
757+
760758
for (; len > 0; len--) {
761759
//if (*cp == '%' && len > 2 && Scan_Hex2(cp+1, &n, FALSE)) {
762760
if (*cp == '%') {
763761
if (len <= 2 || !Scan_Hex2(cp+1, &n, FALSE)) return 0;
764762
*str++ = (REBYTE)n;
765-
cp += 3;
763+
cp += 3;
766764
len -= 2;
765+
cnt -= 2;
767766
}
768767
else *str++ = *cp++;
769768
}
770769
*str = 0;
771-
VAL_TAIL(value) = (REBCNT)(str - VAL_BIN(value));
770+
771+
VAL_SERIES(value) = Decode_UTF_String(BIN_DATA(BUF_FORM), cnt, 8, FALSE);
772+
VAL_INDEX(value) = 0;
772773
VAL_SET(value, REB_URL);
773774
return cp;
774775
}

src/tests/units/mold-test.r3

+20
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,26 @@ Rebol [
172172

173173
===end-group===
174174

175+
===start-group=== "url"
176+
177+
--test-- "mold url"
178+
--assert "ftp://" = mold ftp://
179+
--assert "ftp://š" = mold ftp://š
180+
--assert "ftp://+" = mold ftp://+
181+
--assert "ftp://+" = mold ftp://%2b
182+
--assert "ftp://+" = mold ftp://%2B
183+
--assert "ftp://%20" = mold ftp://%20
184+
--test-- "mold append url"
185+
--assert "ftp://a" = mold append ftp:// #"a"
186+
--assert "ftp://a" = mold append ftp:// "a"
187+
--assert "ftp://š" = mold append ftp:// "š"
188+
--assert "ftp://+" = mold append ftp:// "+"
189+
--assert "ftp://%2528" = mold append ftp:// "%28"
190+
--assert "ftp://%28" = dehex mold append ftp:// "%28"
191+
192+
===end-group===
193+
194+
175195
===start-group=== "mold-all"
176196

177197
--test-- "mold-true" --assert "true" = mold true

0 commit comments

Comments
 (0)