URL encoding/decoding uses UTF-8 now
parent
c75b51bd58
commit
1e477cfc4a
|
@ -14,3 +14,5 @@ IN: temporary
|
|||
[ "hello world" ] [ "hello world%x" url-decode ] unit-test
|
||||
[ "hello%20world" ] [ "hello world" url-encode ] unit-test
|
||||
[ "%20%21%20" ] [ " ! " url-encode ] unit-test
|
||||
|
||||
[ "\u001234hi\u002045" ] [ "\u001234hi\u002045" url-encode url-decode ] unit-test
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
! Copyright (C) 2003, 2007 Slava Pestov.
|
||||
! See http://factorcode.org/license.txt for BSD license.
|
||||
USING: hashtables io kernel math namespaces math.parser assocs
|
||||
sequences strings splitting ascii ;
|
||||
sequences strings splitting ascii io.utf8 ;
|
||||
IN: http
|
||||
|
||||
: header-line ( line -- )
|
||||
|
@ -22,16 +22,13 @@ IN: http
|
|||
over digit? or
|
||||
swap "/_-." member? or ; foldable
|
||||
|
||||
: push-utf8 ( string -- )
|
||||
1string encode-utf8 [ CHAR: % , >hex 2 CHAR: 0 pad-left % ] each ;
|
||||
|
||||
: url-encode ( str -- str )
|
||||
[
|
||||
[
|
||||
dup url-quotable? [
|
||||
,
|
||||
] [
|
||||
CHAR: % , >hex 2 CHAR: 0 pad-left %
|
||||
] if
|
||||
] each
|
||||
] "" make ;
|
||||
[ [
|
||||
dup url-quotable? [ , ] [ push-utf8 ] if
|
||||
] each ] "" make ;
|
||||
|
||||
: url-decode-hex ( index str -- )
|
||||
2dup length 2 - >= [
|
||||
|
@ -58,7 +55,7 @@ IN: http
|
|||
] if ;
|
||||
|
||||
: url-decode ( str -- str )
|
||||
[ 0 swap url-decode-iter ] "" make ;
|
||||
[ 0 swap url-decode-iter ] "" make decode-utf8 ;
|
||||
|
||||
: hash>query ( hash -- str )
|
||||
[ [ url-encode ] 2apply "=" swap 3append ] { } assoc>map
|
||||
|
|
Loading…
Reference in New Issue