Skip to content

Commit

Permalink
FIX: MOLD of URL containing unicode chars is invalid
Browse files Browse the repository at this point in the history
fixes: metaeducation/rebol-issues#2379
(This was actually a lexer error)
Oldes committed Jun 6, 2019
1 parent 76c87a9 commit a8b9ac9
Showing 2 changed files with 28 additions and 7 deletions.
15 changes: 8 additions & 7 deletions src/core/l-types.c
Original file line number Diff line number Diff line change
@@ -742,8 +742,9 @@ bad_hex: Trap0(RE_INVALID_CHARS);
**
***********************************************************************/
{
REBYTE *str;
REBUNI n;
REBYTE *str = Reset_Buffer(BUF_FORM, len);
REBCNT cnt = len;

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

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

VAL_SERIES(value) = Make_Binary(len);
VAL_INDEX(value) = 0;

str = VAL_BIN(value);

for (; len > 0; len--) {
//if (*cp == '%' && len > 2 && Scan_Hex2(cp+1, &n, FALSE)) {
if (*cp == '%') {
if (len <= 2 || !Scan_Hex2(cp+1, &n, FALSE)) return 0;
*str++ = (REBYTE)n;
cp += 3;
cp += 3;
len -= 2;
cnt -= 2;
}
else *str++ = *cp++;
}
*str = 0;
VAL_TAIL(value) = (REBCNT)(str - VAL_BIN(value));

VAL_SERIES(value) = Decode_UTF_String(BIN_DATA(BUF_FORM), cnt, 8, FALSE);
VAL_INDEX(value) = 0;
VAL_SET(value, REB_URL);
return cp;
}
20 changes: 20 additions & 0 deletions src/tests/units/mold-test.r3
Original file line number Diff line number Diff line change
@@ -172,6 +172,26 @@ Rebol [

===end-group===

===start-group=== "url"

--test-- "mold url"
--assert "ftp://" = mold ftp://
--assert "ftp://š" = mold ftp://š
--assert "ftp://+" = mold ftp://+
--assert "ftp://+" = mold ftp://%2b
--assert "ftp://+" = mold ftp://%2B
--assert "ftp://%20" = mold ftp://%20
--test-- "mold append url"
--assert "ftp://a" = mold append ftp:// #"a"
--assert "ftp://a" = mold append ftp:// "a"
--assert "ftp://š" = mold append ftp:// "š"
--assert "ftp://+" = mold append ftp:// "+"
--assert "ftp://%2528" = mold append ftp:// "%28"
--assert "ftp://%28" = dehex mold append ftp:// "%28"

===end-group===


===start-group=== "mold-all"

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

0 comments on commit a8b9ac9

Please sign in to comment.