Software / code / prosody
Comparison
tests/test_util_http.lua @ 5720:449399a7e136
Merge
| author | Matthew Wild <mwild1@gmail.com> |
|---|---|
| date | Sat, 29 Jun 2013 14:45:47 +0100 |
| parent | 5604:6df0ec991f2e |
| child | 5776:bd0ff8ae98a8 |
comparison
equal
deleted
inserted
replaced
| 5719:84025249fc04 | 5720:449399a7e136 |
|---|---|
| 1 -- Prosody IM | |
| 2 -- Copyright (C) 2008-2010 Matthew Wild | |
| 3 -- Copyright (C) 2008-2010 Waqas Hussain | |
| 4 -- | |
| 5 -- This project is MIT/X11 licensed. Please see the | |
| 6 -- COPYING file in the source package for more information. | |
| 7 -- | |
| 8 | |
| 9 function urlencode(urlencode) | |
| 10 assert_equal(urlencode("helloworld123"), "helloworld123", "Normal characters not escaped"); | |
| 11 assert_equal(urlencode("hello world"), "hello%20world", "Spaces escaped"); | |
| 12 assert_equal(urlencode("This & that = something"), "This%20%26%20that%20%3d%20something", "Important URL chars escaped"); | |
| 13 end | |
| 14 | |
| 15 function urldecode(urldecode) | |
| 16 assert_equal("helloworld123", urldecode("helloworld123"), "Normal characters not escaped"); | |
| 17 assert_equal("hello world", urldecode("hello%20world"), "Spaces escaped"); | |
| 18 assert_equal("This & that = something", urldecode("This%20%26%20that%20%3d%20something"), "Important URL chars escaped"); | |
| 19 assert_equal("This & that = something", urldecode("This%20%26%20that%20%3D%20something"), "Important URL chars escaped"); | |
| 20 end | |
| 21 | |
| 22 function formencode(formencode) | |
| 23 assert_equal(formencode({ { name = "one", value = "1"}, { name = "two", value = "2" } }), "one=1&two=2", "Form encoded"); | |
| 24 assert_equal(formencode({ { name = "one two", value = "1"}, { name = "two one&", value = "2" } }), "one+two=1&two+one%26=2", "Form encoded"); | |
| 25 end | |
| 26 | |
| 27 function formdecode(formdecode) | |
| 28 local t = formdecode("one=1&two=2"); | |
| 29 assert_table(t[1]); | |
| 30 assert_equal(t[1].name, "one"); assert_equal(t[1].value, "1"); | |
| 31 assert_table(t[2]); | |
| 32 assert_equal(t[2].name, "two"); assert_equal(t[2].value, "2"); | |
| 33 | |
| 34 local t = formdecode("one+two=1&two+one%26=2"); | |
| 35 assert_equal(t[1].name, "one two"); assert_equal(t[1].value, "1"); | |
| 36 assert_equal(t[2].name, "two one&"); assert_equal(t[2].value, "2"); | |
| 37 end |