aboutsummaryrefslogtreecommitdiffstats
path: root/tests/test_util_http.lua
diff options
context:
space:
mode:
authorMatthew Wild <mwild1@gmail.com>2014-04-02 17:41:38 +0100
committerMatthew Wild <mwild1@gmail.com>2014-04-02 17:41:38 +0100
commit27b4049481f29dcac2d6093c40ad7e8bf1ea8899 (patch)
tree39ca42dddf3935546a0c3c37b2e2456a554899f1 /tests/test_util_http.lua
parentae885de6a2f36eacd6085e7582e5019882208d23 (diff)
parent8c0d996be4f47b77a02668474d3d8a0a41bd0f98 (diff)
downloadprosody-27b4049481f29dcac2d6093c40ad7e8bf1ea8899.tar.gz
prosody-27b4049481f29dcac2d6093c40ad7e8bf1ea8899.zip
Merge 0.9->0.10
Diffstat (limited to 'tests/test_util_http.lua')
-rw-r--r--tests/test_util_http.lua37
1 files changed, 37 insertions, 0 deletions
diff --git a/tests/test_util_http.lua b/tests/test_util_http.lua
new file mode 100644
index 00000000..a195df6b
--- /dev/null
+++ b/tests/test_util_http.lua
@@ -0,0 +1,37 @@
+-- Prosody IM
+-- Copyright (C) 2008-2010 Matthew Wild
+-- Copyright (C) 2008-2010 Waqas Hussain
+--
+-- This project is MIT/X11 licensed. Please see the
+-- COPYING file in the source package for more information.
+--
+
+function urlencode(urlencode)
+ assert_equal(urlencode("helloworld123"), "helloworld123", "Normal characters not escaped");
+ assert_equal(urlencode("hello world"), "hello%20world", "Spaces escaped");
+ assert_equal(urlencode("This & that = something"), "This%20%26%20that%20%3d%20something", "Important URL chars escaped");
+end
+
+function urldecode(urldecode)
+ assert_equal("helloworld123", urldecode("helloworld123"), "Normal characters not escaped");
+ assert_equal("hello world", urldecode("hello%20world"), "Spaces escaped");
+ assert_equal("This & that = something", urldecode("This%20%26%20that%20%3d%20something"), "Important URL chars escaped");
+ assert_equal("This & that = something", urldecode("This%20%26%20that%20%3D%20something"), "Important URL chars escaped");
+end
+
+function formencode(formencode)
+ assert_equal(formencode({ { name = "one", value = "1"}, { name = "two", value = "2" } }), "one=1&two=2", "Form encoded");
+ assert_equal(formencode({ { name = "one two", value = "1"}, { name = "two one&", value = "2" } }), "one+two=1&two+one%26=2", "Form encoded");
+end
+
+function formdecode(formdecode)
+ local t = formdecode("one=1&two=2");
+ assert_table(t[1]);
+ assert_equal(t[1].name, "one"); assert_equal(t[1].value, "1");
+ assert_table(t[2]);
+ assert_equal(t[2].name, "two"); assert_equal(t[2].value, "2");
+
+ local t = formdecode("one+two=1&two+one%26=2");
+ assert_equal(t[1].name, "one two"); assert_equal(t[1].value, "1");
+ assert_equal(t[2].name, "two one&"); assert_equal(t[2].value, "2");
+end