Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
mtxclient
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Nheko Reborn
mtxclient
Commits
e6ab5866
Commit
e6ab5866
authored
6 years ago
by
Konstantinos Sideris
Browse files
Options
Downloads
Patches
Plain Diff
Add URL encoding for query params
parent
dbb47233
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
include/mtxclient/utils.hpp
+4
-0
4 additions, 0 deletions
include/mtxclient/utils.hpp
lib/utils.cpp
+28
-2
28 additions, 2 deletions
lib/utils.cpp
tests/media_api.cpp
+7
-0
7 additions, 0 deletions
tests/media_api.cpp
with
39 additions
and
2 deletions
include/mtxclient/utils.hpp
+
4
−
0
View file @
e6ab5866
...
...
@@ -39,6 +39,10 @@ query_params(const std::map<std::string, std::string> ¶ms) noexcept;
std
::
string
decompress
(
const
boost
::
iostreams
::
array_source
&
src
,
const
std
::
string
&
type
)
noexcept
;
//! URL-encode the input string.
std
::
string
url_encode
(
const
std
::
string
&
s
)
noexcept
;
template
<
class
T
>
inline
T
deserialize
(
const
std
::
string
&
data
)
...
...
This diff is collapsed.
Click to expand it.
lib/utils.cpp
+
28
−
2
View file @
e6ab5866
...
...
@@ -78,14 +78,14 @@ mtx::client::utils::query_params(const std::map<std::string, std::string> ¶m
auto
pb
=
params
.
cbegin
();
auto
pe
=
params
.
cend
();
std
::
string
data
=
pb
->
first
+
"="
+
pb
->
second
;
std
::
string
data
=
pb
->
first
+
"="
+
url_encode
(
pb
->
second
)
;
++
pb
;
if
(
pb
==
pe
)
return
data
;
for
(;
pb
!=
pe
;
++
pb
)
data
+=
"&"
+
pb
->
first
+
"="
+
pb
->
second
;
data
+=
"&"
+
pb
->
first
+
"="
+
url_encode
(
pb
->
second
)
;
return
data
;
}
...
...
@@ -109,3 +109,29 @@ mtx::client::utils::decompress(const boost::iostreams::array_source &src,
return
decompressed
.
str
();
}
std
::
string
mtx
::
client
::
utils
::
url_encode
(
const
std
::
string
&
value
)
noexcept
{
// https: // stackoverflow.com/questions/154536/encode-decode-urls-in-c
std
::
ostringstream
escaped
;
escaped
.
fill
(
'0'
);
escaped
<<
std
::
hex
;
for
(
auto
i
=
value
.
begin
(),
n
=
value
.
end
();
i
!=
n
;
++
i
)
{
std
::
string
::
value_type
c
=
(
*
i
);
// Keep alphanumeric and other accepted characters intact
if
(
std
::
isalnum
(
c
)
||
c
==
'-'
||
c
==
'_'
||
c
==
'.'
||
c
==
'~'
)
{
escaped
<<
c
;
continue
;
}
// Any other characters are percent-encoded
escaped
<<
std
::
uppercase
;
escaped
<<
'%'
<<
std
::
setw
(
2
)
<<
int
((
unsigned
char
)
c
);
escaped
<<
std
::
nouppercase
;
}
return
escaped
.
str
();
}
This diff is collapsed.
Click to expand it.
tests/media_api.cpp
+
7
−
0
View file @
e6ab5866
...
...
@@ -104,6 +104,13 @@ TEST(MediaAPI, UploadImage)
const
auto
img
=
read_file
(
"./fixtures/test.jpeg"
);
carl
->
upload
(
img
,
"image/jpeg"
,
"a name that needs to be encode/d.jpeg"
,
[
carl
,
img
](
const
mtx
::
responses
::
ContentURI
&
res
,
RequestErr
err
)
{
validate_upload
(
res
,
err
);
});
carl
->
upload
(
img
,
"image/jpeg"
,
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment