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