Annotate

tests/test_util_http.lua @ 6102:385772166289

plugins/muc/muc: Add copyright for daurnimator
author daurnimator <quae@daurnimator.com>
date Tue, 18 Mar 2014 14:54:41 -0400
parent 5776:bd0ff8ae98a8
child 7514:ea58c0fe1cd7
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4339
63304d323983 tests/test.lua, tests/test_net_http.lua: Tests for net.http's url and form encoding/decoding functions
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
1 -- Prosody IM
63304d323983 tests/test.lua, tests/test_net_http.lua: Tests for net.http's url and form encoding/decoding functions
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
2 -- Copyright (C) 2008-2010 Matthew Wild
63304d323983 tests/test.lua, tests/test_net_http.lua: Tests for net.http's url and form encoding/decoding functions
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
3 -- Copyright (C) 2008-2010 Waqas Hussain
5776
bd0ff8ae98a8 Remove all trailing whitespace
Florian Zeitz <florob@babelmonkeys.de>
parents: 5604
diff changeset
4 --
4339
63304d323983 tests/test.lua, tests/test_net_http.lua: Tests for net.http's url and form encoding/decoding functions
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
5 -- This project is MIT/X11 licensed. Please see the
63304d323983 tests/test.lua, tests/test_net_http.lua: Tests for net.http's url and form encoding/decoding functions
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
6 -- COPYING file in the source package for more information.
63304d323983 tests/test.lua, tests/test_net_http.lua: Tests for net.http's url and form encoding/decoding functions
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
7 --
63304d323983 tests/test.lua, tests/test_net_http.lua: Tests for net.http's url and form encoding/decoding functions
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
8
63304d323983 tests/test.lua, tests/test_net_http.lua: Tests for net.http's url and form encoding/decoding functions
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
9 function urlencode(urlencode)
63304d323983 tests/test.lua, tests/test_net_http.lua: Tests for net.http's url and form encoding/decoding functions
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
10 assert_equal(urlencode("helloworld123"), "helloworld123", "Normal characters not escaped");
63304d323983 tests/test.lua, tests/test_net_http.lua: Tests for net.http's url and form encoding/decoding functions
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
11 assert_equal(urlencode("hello world"), "hello%20world", "Spaces escaped");
63304d323983 tests/test.lua, tests/test_net_http.lua: Tests for net.http's url and form encoding/decoding functions
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
12 assert_equal(urlencode("This & that = something"), "This%20%26%20that%20%3d%20something", "Important URL chars escaped");
63304d323983 tests/test.lua, tests/test_net_http.lua: Tests for net.http's url and form encoding/decoding functions
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
13 end
63304d323983 tests/test.lua, tests/test_net_http.lua: Tests for net.http's url and form encoding/decoding functions
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
14
63304d323983 tests/test.lua, tests/test_net_http.lua: Tests for net.http's url and form encoding/decoding functions
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
15 function urldecode(urldecode)
63304d323983 tests/test.lua, tests/test_net_http.lua: Tests for net.http's url and form encoding/decoding functions
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
16 assert_equal("helloworld123", urldecode("helloworld123"), "Normal characters not escaped");
63304d323983 tests/test.lua, tests/test_net_http.lua: Tests for net.http's url and form encoding/decoding functions
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
17 assert_equal("hello world", urldecode("hello%20world"), "Spaces escaped");
63304d323983 tests/test.lua, tests/test_net_http.lua: Tests for net.http's url and form encoding/decoding functions
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
18 assert_equal("This & that = something", urldecode("This%20%26%20that%20%3d%20something"), "Important URL chars escaped");
63304d323983 tests/test.lua, tests/test_net_http.lua: Tests for net.http's url and form encoding/decoding functions
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
19 assert_equal("This & that = something", urldecode("This%20%26%20that%20%3D%20something"), "Important URL chars escaped");
63304d323983 tests/test.lua, tests/test_net_http.lua: Tests for net.http's url and form encoding/decoding functions
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
20 end
63304d323983 tests/test.lua, tests/test_net_http.lua: Tests for net.http's url and form encoding/decoding functions
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
21
63304d323983 tests/test.lua, tests/test_net_http.lua: Tests for net.http's url and form encoding/decoding functions
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
22 function formencode(formencode)
63304d323983 tests/test.lua, tests/test_net_http.lua: Tests for net.http's url and form encoding/decoding functions
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
23 assert_equal(formencode({ { name = "one", value = "1"}, { name = "two", value = "2" } }), "one=1&two=2", "Form encoded");
63304d323983 tests/test.lua, tests/test_net_http.lua: Tests for net.http's url and form encoding/decoding functions
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
24 assert_equal(formencode({ { name = "one two", value = "1"}, { name = "two one&", value = "2" } }), "one+two=1&two+one%26=2", "Form encoded");
63304d323983 tests/test.lua, tests/test_net_http.lua: Tests for net.http's url and form encoding/decoding functions
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
25 end
63304d323983 tests/test.lua, tests/test_net_http.lua: Tests for net.http's url and form encoding/decoding functions
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
26
63304d323983 tests/test.lua, tests/test_net_http.lua: Tests for net.http's url and form encoding/decoding functions
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
27 function formdecode(formdecode)
63304d323983 tests/test.lua, tests/test_net_http.lua: Tests for net.http's url and form encoding/decoding functions
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
28 local t = formdecode("one=1&two=2");
63304d323983 tests/test.lua, tests/test_net_http.lua: Tests for net.http's url and form encoding/decoding functions
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
29 assert_table(t[1]);
63304d323983 tests/test.lua, tests/test_net_http.lua: Tests for net.http's url and form encoding/decoding functions
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
30 assert_equal(t[1].name, "one"); assert_equal(t[1].value, "1");
63304d323983 tests/test.lua, tests/test_net_http.lua: Tests for net.http's url and form encoding/decoding functions
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
31 assert_table(t[2]);
63304d323983 tests/test.lua, tests/test_net_http.lua: Tests for net.http's url and form encoding/decoding functions
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
32 assert_equal(t[2].name, "two"); assert_equal(t[2].value, "2");
63304d323983 tests/test.lua, tests/test_net_http.lua: Tests for net.http's url and form encoding/decoding functions
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
33
63304d323983 tests/test.lua, tests/test_net_http.lua: Tests for net.http's url and form encoding/decoding functions
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
34 local t = formdecode("one+two=1&two+one%26=2");
63304d323983 tests/test.lua, tests/test_net_http.lua: Tests for net.http's url and form encoding/decoding functions
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
35 assert_equal(t[1].name, "one two"); assert_equal(t[1].value, "1");
63304d323983 tests/test.lua, tests/test_net_http.lua: Tests for net.http's url and form encoding/decoding functions
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
36 assert_equal(t[2].name, "two one&"); assert_equal(t[2].value, "2");
63304d323983 tests/test.lua, tests/test_net_http.lua: Tests for net.http's url and form encoding/decoding functions
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
37 end