]>
git.proxmox.com Git - libgit2.git/blob - tests/str/percent.c
1 #include "clar_libgit2.h"
3 static void expect_decode_pass(const char *expected
, const char *encoded
)
5 git_str in
= GIT_STR_INIT
, out
= GIT_STR_INIT
;
8 * ensure that we only read the given length of the input buffer
9 * by putting garbage at the end. this will ensure that we do
10 * not, eg, rely on nul-termination or walk off the end of the buf.
12 cl_git_pass(git_str_puts(&in
, encoded
));
13 cl_git_pass(git_str_PUTS(&in
, "TRAILER"));
15 cl_git_pass(git_str_decode_percent(&out
, in
.ptr
, strlen(encoded
)));
17 cl_assert_equal_s(expected
, git_str_cstr(&out
));
18 cl_assert_equal_i(strlen(expected
), git_str_len(&out
));
21 git_str_dispose(&out
);
24 void test_str_percent__decode_succeeds(void)
26 expect_decode_pass("", "");
27 expect_decode_pass(" ", "%20");
28 expect_decode_pass("a", "a");
29 expect_decode_pass(" a", "%20a");
30 expect_decode_pass("a ", "a%20");
31 expect_decode_pass("github.com", "github.com");
32 expect_decode_pass("github.com", "githu%62.com");
33 expect_decode_pass("github.com", "github%2ecom");
34 expect_decode_pass("foo bar baz", "foo%20bar%20baz");
35 expect_decode_pass("foo bar baz", "foo%20bar%20baz");
36 expect_decode_pass("foo bar ", "foo%20bar%20");
39 void test_str_percent__ignores_invalid(void)
41 expect_decode_pass("githu%%.com", "githu%%.com");
42 expect_decode_pass("github.co%2", "github.co%2");
43 expect_decode_pass("github%2.com", "github%2.com");
44 expect_decode_pass("githu%2z.com", "githu%2z.com");
45 expect_decode_pass("github.co%9z", "github.co%9z");
46 expect_decode_pass("github.co%2", "github.co%2");
47 expect_decode_pass("github.co%", "github.co%");