Adding url-encode-full to urls.encoding to do url encoding properly
parent
030619114f
commit
4e268ea567
|
@ -7,7 +7,11 @@ HELP: url-decode
|
||||||
|
|
||||||
HELP: url-encode
|
HELP: url-encode
|
||||||
{ $values { "str" string } { "encoded" string } }
|
{ $values { "str" string } { "encoded" string } }
|
||||||
{ $description "URL-encodes a string." } ;
|
{ $description "URL-encodes a string, excluding certain characters, such as \"/\"." } ;
|
||||||
|
|
||||||
|
HELP: url-encode-full
|
||||||
|
{ $values { "str" string } { "encoded" string } }
|
||||||
|
{ $description "URL-encodes a string, including all reserved characters, such as \"/\"." } ;
|
||||||
|
|
||||||
HELP: url-quotable?
|
HELP: url-quotable?
|
||||||
{ $values { "ch" "a character" } { "?" "a boolean" } }
|
{ $values { "ch" "a character" } { "?" "a boolean" } }
|
||||||
|
|
|
@ -14,6 +14,25 @@ IN: urls.encoding
|
||||||
[ "/_-.:" member? ]
|
[ "/_-.:" member? ]
|
||||||
} 1|| ; foldable
|
} 1|| ; foldable
|
||||||
|
|
||||||
|
! see http://tools.ietf.org/html/rfc3986#section-2.2
|
||||||
|
: gen-delim? ( ch -- ? )
|
||||||
|
":/?#[]@" member? ; foldable
|
||||||
|
|
||||||
|
: sub-delim? ( ch -- ? )
|
||||||
|
"!$&'()*+,;=" member? ; foldable
|
||||||
|
|
||||||
|
: reserved? ( ch -- ? )
|
||||||
|
[ gen-delim? ] [ sub-delim? ] bi or ; foldable
|
||||||
|
|
||||||
|
! see http://tools.ietf.org/html/rfc3986#section-2.3
|
||||||
|
: unreserved? ( ch -- ? )
|
||||||
|
{
|
||||||
|
[ letter? ]
|
||||||
|
[ LETTER? ]
|
||||||
|
[ digit? ]
|
||||||
|
[ "-._~" member? ]
|
||||||
|
} 1|| ; foldable
|
||||||
|
|
||||||
<PRIVATE
|
<PRIVATE
|
||||||
|
|
||||||
: push-utf8 ( ch -- )
|
: push-utf8 ( ch -- )
|
||||||
|
@ -27,6 +46,11 @@ PRIVATE>
|
||||||
[ dup url-quotable? [ , ] [ push-utf8 ] if ] each
|
[ dup url-quotable? [ , ] [ push-utf8 ] if ] each
|
||||||
] "" make ;
|
] "" make ;
|
||||||
|
|
||||||
|
: url-encode-full ( str -- encoded )
|
||||||
|
[
|
||||||
|
[ dup unreserved? [ , ] [ push-utf8 ] if ] each
|
||||||
|
] "" make ;
|
||||||
|
|
||||||
<PRIVATE
|
<PRIVATE
|
||||||
|
|
||||||
: url-decode-hex ( index str -- )
|
: url-decode-hex ( index str -- )
|
||||||
|
|
Loading…
Reference in New Issue