Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
git2
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
lvzhengyang
git2
Commits
459e2dcd
Commit
459e2dcd
authored
Dec 27, 2011
by
nulltoken
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
path: add git__percent_decode()
parent
eb8de747
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
66 additions
and
3 deletions
+66
-3
src/path.c
+35
-0
src/path.h
+2
-0
tests-clay/clay.h
+1
-0
tests-clay/clay_main.c
+4
-3
tests-clay/core/path.c
+24
-0
No files found.
src/path.c
View file @
459e2dcd
...
@@ -237,3 +237,38 @@ void git_path_string_to_dir(char* path, size_t size)
...
@@ -237,3 +237,38 @@ void git_path_string_to_dir(char* path, size_t size)
}
}
}
}
int
git__percent_decode
(
git_buf
*
decoded_out
,
const
char
*
input
)
{
int
len
,
hi
,
lo
,
i
,
error
=
GIT_SUCCESS
;
assert
(
decoded_out
&&
input
);
len
=
strlen
(
input
);
git_buf_clear
(
decoded_out
);
for
(
i
=
0
;
i
<
len
;
i
++
)
{
char
c
=
input
[
i
];
if
(
c
!=
'%'
)
goto
append
;
if
(
i
>=
len
-
2
)
goto
append
;
hi
=
git__fromhex
(
input
[
i
+
1
]);
lo
=
git__fromhex
(
input
[
i
+
2
]);
if
(
hi
<
0
||
lo
<
0
)
goto
append
;
c
=
(
char
)(
hi
<<
4
|
lo
);
i
+=
2
;
append:
error
=
git_buf_putc
(
decoded_out
,
c
);
if
(
error
<
GIT_SUCCESS
)
return
git__rethrow
(
error
,
"Failed to percent decode '%s'."
,
input
);
}
return
error
;
}
src/path.h
View file @
459e2dcd
...
@@ -74,4 +74,6 @@ GIT_INLINE(void) git_path_mkposix(char *path)
...
@@ -74,4 +74,6 @@ GIT_INLINE(void) git_path_mkposix(char *path)
# define git_path_mkposix(p)
/* blank */
# define git_path_mkposix(p)
/* blank */
#endif
#endif
extern
int
git__percent_decode
(
git_buf
*
decoded_out
,
const
char
*
input
);
#endif
#endif
tests-clay/clay.h
View file @
459e2dcd
...
@@ -116,6 +116,7 @@ extern void test_core_path__5_joins(void);
...
@@ -116,6 +116,7 @@ extern void test_core_path__5_joins(void);
extern
void
test_core_path__6_long_joins
(
void
);
extern
void
test_core_path__6_long_joins
(
void
);
extern
void
test_core_path__7_path_to_dir
(
void
);
extern
void
test_core_path__7_path_to_dir
(
void
);
extern
void
test_core_path__8_self_join
(
void
);
extern
void
test_core_path__8_self_join
(
void
);
extern
void
test_core_path__9_percent_decode
(
void
);
extern
void
test_core_rmdir__delete_recursive
(
void
);
extern
void
test_core_rmdir__delete_recursive
(
void
);
extern
void
test_core_rmdir__fail_to_delete_non_empty_dir
(
void
);
extern
void
test_core_rmdir__fail_to_delete_non_empty_dir
(
void
);
extern
void
test_core_rmdir__initialize
(
void
);
extern
void
test_core_rmdir__initialize
(
void
);
...
...
tests-clay/clay_main.c
View file @
459e2dcd
...
@@ -180,7 +180,8 @@ static const struct clay_func _clay_cb_core_path[] = {
...
@@ -180,7 +180,8 @@ static const struct clay_func _clay_cb_core_path[] = {
{
"5_joins"
,
&
test_core_path__5_joins
},
{
"5_joins"
,
&
test_core_path__5_joins
},
{
"6_long_joins"
,
&
test_core_path__6_long_joins
},
{
"6_long_joins"
,
&
test_core_path__6_long_joins
},
{
"7_path_to_dir"
,
&
test_core_path__7_path_to_dir
},
{
"7_path_to_dir"
,
&
test_core_path__7_path_to_dir
},
{
"8_self_join"
,
&
test_core_path__8_self_join
}
{
"8_self_join"
,
&
test_core_path__8_self_join
},
{
"9_percent_decode"
,
&
test_core_path__9_percent_decode
}
};
};
static
const
struct
clay_func
_clay_cb_core_rmdir
[]
=
{
static
const
struct
clay_func
_clay_cb_core_rmdir
[]
=
{
{
"delete_recursive"
,
&
test_core_rmdir__delete_recursive
},
{
"delete_recursive"
,
&
test_core_rmdir__delete_recursive
},
...
@@ -381,7 +382,7 @@ static const struct clay_suite _clay_suites[] = {
...
@@ -381,7 +382,7 @@ static const struct clay_suite _clay_suites[] = {
"core::path"
,
"core::path"
,
{
NULL
,
NULL
},
{
NULL
,
NULL
},
{
NULL
,
NULL
},
{
NULL
,
NULL
},
_clay_cb_core_path
,
7
_clay_cb_core_path
,
8
},
},
{
{
"core::rmdir"
,
"core::rmdir"
,
...
@@ -548,7 +549,7 @@ static const struct clay_suite _clay_suites[] = {
...
@@ -548,7 +549,7 @@ static const struct clay_suite _clay_suites[] = {
};
};
static
size_t
_clay_suite_count
=
39
;
static
size_t
_clay_suite_count
=
39
;
static
size_t
_clay_callback_count
=
12
3
;
static
size_t
_clay_callback_count
=
12
4
;
/* Core test functions */
/* Core test functions */
static
void
static
void
...
...
tests-clay/core/path.c
View file @
459e2dcd
...
@@ -273,3 +273,27 @@ void test_core_path__8_self_join(void)
...
@@ -273,3 +273,27 @@ void test_core_path__8_self_join(void)
git_buf_free
(
&
path
);
git_buf_free
(
&
path
);
}
}
static
void
check_percent_decoding
(
const
char
*
expected_result
,
const
char
*
input
)
{
git_buf
buf
=
GIT_BUF_INIT
;
cl_git_pass
(
git__percent_decode
(
&
buf
,
input
));
cl_assert_strequal
(
expected_result
,
git_buf_cstr
(
&
buf
));
git_buf_free
(
&
buf
);
}
void
test_core_path__9_percent_decode
(
void
)
{
check_percent_decoding
(
"abcd"
,
"abcd"
);
check_percent_decoding
(
"a2%"
,
"a2%"
);
check_percent_decoding
(
"a2%3"
,
"a2%3"
);
check_percent_decoding
(
"a2%%3"
,
"a2%%3"
);
check_percent_decoding
(
"a2%3z"
,
"a2%3z"
);
check_percent_decoding
(
"a,"
,
"a%2c"
);
check_percent_decoding
(
"a21"
,
"a2%31"
);
check_percent_decoding
(
"a2%1"
,
"a2%%31"
);
check_percent_decoding
(
"a bc "
,
"a%20bc%20"
);
check_percent_decoding
(
"Vicent Mart"
"
\355
"
,
"Vicent%20Mart%ED"
);
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment