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
9181e4b5
Unverified
Commit
9181e4b5
authored
Jan 10, 2020
by
Patrick Steinhardt
Committed by
GitHub
Jan 10, 2020
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #5339 from josharian/issue-5321
netops: handle intact query parameters in service_suffix removal
parents
258188dd
7142964f
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
45 additions
and
8 deletions
+45
-8
src/netops.c
+29
-8
tests/network/redirect.c
+16
-0
No files found.
src/netops.c
View file @
9181e4b5
...
...
@@ -171,25 +171,46 @@ int gitno_connection_data_handle_redirect(
/* Remove the service suffix if it was given to us */
if
(
service_suffix
)
{
/*
* Some servers strip the query parameters from the Location header
* when sending a redirect. Others leave it in place.
* Check for both, starting with the stripped case first,
* since it appears to be more common.
*/
const
char
*
service_query
=
strchr
(
service_suffix
,
'?'
);
size_t
full_suffix_len
=
strlen
(
service_suffix
);
size_t
suffix_len
=
service_query
?
(
size_t
)(
service_query
-
service_suffix
)
:
strlen
(
service_suffix
)
;
(
size_t
)(
service_query
-
service_suffix
)
:
full_suffix_len
;
size_t
path_len
=
strlen
(
url
->
path
);
ssize_t
truncate
=
-
1
;
/* Check for a redirect without query parameters, like "/newloc/info/refs" */
if
(
suffix_len
&&
path_len
>=
suffix_len
)
{
size_t
suffix_offset
=
path_len
-
suffix_len
;
if
(
git__strncmp
(
url
->
path
+
suffix_offset
,
service_suffix
,
suffix_len
)
==
0
&&
(
!
service_query
||
git__strcmp
(
url
->
query
,
service_query
+
1
)
==
0
))
{
/* Ensure we leave a minimum of '/' as the path */
if
(
suffix_offset
==
0
)
suffix_offset
++
;
truncate
=
suffix_offset
;
}
}
url
->
path
[
suffix_offset
]
=
'\0'
;
/*
* If we haven't already found where to truncate to remove the suffix,
* check for a redirect with query parameters,
* like "/newloc/info/refs?service=git-upload-pack"
*/
if
(
truncate
==
-
1
&&
git__suffixcmp
(
url
->
path
,
service_suffix
)
==
0
)
{
truncate
=
path_len
-
full_suffix_len
;
}
git__free
(
url
->
query
);
url
->
query
=
NULL
;
}
if
(
truncate
>=
0
)
{
/* Ensure we leave a minimum of '/' as the path */
if
(
truncate
==
0
)
truncate
++
;
url
->
path
[
truncate
]
=
'\0'
;
git__free
(
url
->
query
);
url
->
query
=
NULL
;
}
}
...
...
tests/network/redirect.c
View file @
9181e4b5
...
...
@@ -111,3 +111,19 @@ void test_network_redirect__redirect_relative_ssl(void)
cl_assert_equal_p
(
conndata
.
username
,
NULL
);
cl_assert_equal_p
(
conndata
.
password
,
NULL
);
}
void
test_network_redirect__service_query_no_query_params_in_location
(
void
)
{
cl_git_pass
(
git_net_url_parse
(
&
conndata
,
"https://foo.com/bar/info/refs?service=git-upload-pack"
));
cl_git_pass
(
gitno_connection_data_handle_redirect
(
&
conndata
,
"/baz/info/refs"
,
"/info/refs?service=git-upload-pack"
));
cl_assert_equal_s
(
conndata
.
path
,
"/baz"
);
}
void
test_network_redirect__service_query_with_query_params_in_location
(
void
)
{
cl_git_pass
(
git_net_url_parse
(
&
conndata
,
"https://foo.com/bar/info/refs?service=git-upload-pack"
));
cl_git_pass
(
gitno_connection_data_handle_redirect
(
&
conndata
,
"/baz/info/refs?service=git-upload-pack"
,
"/info/refs?service=git-upload-pack"
));
cl_assert_equal_s
(
conndata
.
path
,
"/baz"
);
}
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