urls.encoding: tweak assoc>query to fix problem with OAuth

db4
Slava Pestov 2010-07-06 00:55:36 -04:00
parent f82c6e14ad
commit cbe46baae2
2 changed files with 12 additions and 4 deletions

View File

@ -11,6 +11,12 @@ USING: urls.encoding tools.test arrays kernel assocs present accessors ;
[ "hello world" ] [ "hello world%x" url-decode ] unit-test
[ "hello%20world" ] [ "hello world" url-encode ] unit-test
[ "~foo" ] [ "~foo" url-encode ] unit-test
[ "~foo" ] [ "~foo" url-encode-full ] unit-test
[ ":foo" ] [ ":foo" url-encode ] unit-test
[ "%3Afoo" ] [ ":foo" url-encode-full ] unit-test
[ "hello world" ] [ "hello+world" query-decode ] unit-test
[ "\u001234hi\u002045" ] [ "\u001234hi\u002045" url-encode url-decode ] unit-test
@ -25,6 +31,8 @@ USING: urls.encoding tools.test arrays kernel assocs present accessors ;
[ H{ { "text" "hello world" } } ] [ "text=hello+world" query>assoc ] unit-test
[ "foo=%3A" ] [ { { "foo" ":" } } assoc>query ] unit-test
[ "a=3" ] [ { { "a" 3 } } assoc>query ] unit-test
[ "a" ] [ { { "a" f } } assoc>query ] unit-test

View File

@ -1,4 +1,4 @@
! Copyright (C) 2008 Slava Pestov.
! Copyright (C) 2008, 2010 Slava Pestov.
! See http://factorcode.org/license.txt for BSD license.
USING: kernel ascii combinators combinators.short-circuit
sequences splitting fry namespaces make assocs arrays strings
@ -11,7 +11,7 @@ IN: urls.encoding
[ letter? ]
[ LETTER? ]
[ digit? ]
[ "/_-.:" member? ]
[ "-._~/:" member? ]
} 1|| ; foldable
! see http://tools.ietf.org/html/rfc3986#section-2.2
@ -120,7 +120,7 @@ PRIVATE>
: assoc>query ( assoc -- str )
[
assoc-strings [
[ url-encode ] dip
[ [ url-encode "=" glue , ] with each ] [ , ] if*
[ url-encode-full ] dip
[ [ url-encode-full "=" glue , ] with each ] [ , ] if*
] assoc-each
] { } make "&" join ;