Skip to content

Commit

Permalink
FIX: optimized url/file escape table initialization
Browse files Browse the repository at this point in the history
  • Loading branch information
Oldes committed Apr 14, 2022
1 parent 92c65fc commit 48a3fc2
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/core/s-mold.c
Original file line number Diff line number Diff line change
Expand Up @@ -1590,16 +1590,16 @@ STOID Mold_Error(REBVAL *value, REB_MOLD *mold, REBFLG molded)
URL_Escapes = cp = Make_Mem(MAX_URL_CHAR+1); // cleared
// escape all chars from #"^(00)" to #"^(20)"
for (c = 0; c <= ' '; c++) cp[c] = ESC_URL | ESC_FILE;
// and also all chars which are a lexer delimiters
dc = b_cast(";%\"()[]{}<>");
// and also all chars which are a lexer delimiters + 3 common extra chars
dc = b_cast(";%\"()[]{}<>\x5C\x5E\x7F");
for (c = (REBYTE)LEN_BYTES(dc); c > 0; c--) URL_Escapes[*dc++] = ESC_URL | ESC_FILE;
// RFC3986 allows unescaped only: ALPHA, DIGIT and "-._~:/?#[]@!$&'()*+,;="
// so include also folowing chars for url escaping...
dc = b_cast("\x5C\x5E\x60\x7C\x7F");
for (c = (REBYTE)LEN_BYTES(dc); c > 0; c--) URL_Escapes[*dc++] = ESC_URL;
URL_Escapes['\x60'] |= ESC_URL;
URL_Escapes['\x7C'] |= ESC_URL;
// required file escaping... https://github.com/Oldes/Rebol-issues/issues/2491
dc = b_cast("\x3A\x40\x5C\x5E\x7F");
for (c = (REBYTE)LEN_BYTES(dc); c > 0; c--) URL_Escapes[*dc++] = ESC_FILE;
URL_Escapes['\x3A'] |= ESC_FILE;
URL_Escapes['\x40'] |= ESC_FILE;
}


Expand Down
5 changes: 5 additions & 0 deletions src/tests/units/mold-test.r3
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,11 @@ Rebol [
--assert "ftp://+" = mold append ftp:// "+"
--assert "ftp://%2528" = mold append ftp:// "%28"
--assert "ftp://%28" = dehex mold append ftp:// "%28"
--test-- "mold url escaping"
for i 0 255 1 [
f2: try [load mold f1: append copy a:/ to char! i]
--assert f1 == f2
]

===end-group===

Expand Down

0 comments on commit 48a3fc2

Please sign in to comment.