Skip to content

Commit 48a3fc2

Browse files
committed
FIX: optimized url/file escape table initialization
related to: Oldes/Rebol-issues#2491
1 parent 92c65fc commit 48a3fc2

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

src/core/s-mold.c

+6-6
Original file line numberDiff line numberDiff line change
@@ -1590,16 +1590,16 @@ STOID Mold_Error(REBVAL *value, REB_MOLD *mold, REBFLG molded)
15901590
URL_Escapes = cp = Make_Mem(MAX_URL_CHAR+1); // cleared
15911591
// escape all chars from #"^(00)" to #"^(20)"
15921592
for (c = 0; c <= ' '; c++) cp[c] = ESC_URL | ESC_FILE;
1593-
// and also all chars which are a lexer delimiters
1594-
dc = b_cast(";%\"()[]{}<>");
1593+
// and also all chars which are a lexer delimiters + 3 common extra chars
1594+
dc = b_cast(";%\"()[]{}<>\x5C\x5E\x7F");
15951595
for (c = (REBYTE)LEN_BYTES(dc); c > 0; c--) URL_Escapes[*dc++] = ESC_URL | ESC_FILE;
15961596
// RFC3986 allows unescaped only: ALPHA, DIGIT and "-._~:/?#[]@!$&'()*+,;="
15971597
// so include also folowing chars for url escaping...
1598-
dc = b_cast("\x5C\x5E\x60\x7C\x7F");
1599-
for (c = (REBYTE)LEN_BYTES(dc); c > 0; c--) URL_Escapes[*dc++] = ESC_URL;
1598+
URL_Escapes['\x60'] |= ESC_URL;
1599+
URL_Escapes['\x7C'] |= ESC_URL;
16001600
// required file escaping... https://github.com/Oldes/Rebol-issues/issues/2491
1601-
dc = b_cast("\x3A\x40\x5C\x5E\x7F");
1602-
for (c = (REBYTE)LEN_BYTES(dc); c > 0; c--) URL_Escapes[*dc++] = ESC_FILE;
1601+
URL_Escapes['\x3A'] |= ESC_FILE;
1602+
URL_Escapes['\x40'] |= ESC_FILE;
16031603
}
16041604

16051605

src/tests/units/mold-test.r3

+5
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,11 @@ Rebol [
194194
--assert "ftp://+" = mold append ftp:// "+"
195195
--assert "ftp://%2528" = mold append ftp:// "%28"
196196
--assert "ftp://%28" = dehex mold append ftp:// "%28"
197+
--test-- "mold url escaping"
198+
for i 0 255 1 [
199+
f2: try [load mold f1: append copy a:/ to char! i]
200+
--assert f1 == f2
201+
]
197202

198203
===end-group===
199204

0 commit comments

Comments
 (0)