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
|
||||
{ $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?
|
||||
{ $values { "ch" "a character" } { "?" "a boolean" } }
|
||||
|
|
|
@ -14,6 +14,25 @@ IN: urls.encoding
|
|||
[ "/_-.:" member? ]
|
||||
} 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
|
||||
|
||||
: push-utf8 ( ch -- )
|
||||
|
@ -27,6 +46,11 @@ PRIVATE>
|
|||
[ dup url-quotable? [ , ] [ push-utf8 ] if ] each
|
||||
] "" make ;
|
||||
|
||||
: url-encode-full ( str -- encoded )
|
||||
[
|
||||
[ dup unreserved? [ , ] [ push-utf8 ] if ] each
|
||||
] "" make ;
|
||||
|
||||
<PRIVATE
|
||||
|
||||
: url-decode-hex ( index str -- )
|
||||
|
|
Loading…
Reference in New Issue