Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Laura i Domiś
HTTP.sh
Commits
a0d23e16
Commit
a0d23e16
authored
Apr 02, 2021
by
Dominika Liberda
💽
Browse files
* html_encode bugfix, changed default URL decode algorithm
parent
6b03a481
Pipeline
#348
failed with stage
in 15 seconds
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
src/misc.sh
View file @
a0d23e16
...
...
@@ -39,7 +39,7 @@ function post_dump() {
# html_encode(string)
function
html_encode
()
{
sed
's/</\</g;s/>/\>/g;s/%/\%/g;s/\//\//g;s/\\/\\/g;s/'
"'"
'/\'/g;s/"/\"/g;s/`/\`/g;s/?/\?/g;
s/\&/\&/g
'
<<<
"
$1
"
sed
's/
\&/\&/g;s/
</\</g;s/>/\>/g;s/%/\%/g;s/\//\//g;s/\\/\\/g;s/'
"'"
'/\'/g;s/"/\"/g;s/`/\`/g;s/?/\?/g;'
<<<
"
$1
"
}
# url_encode(string)
...
...
src/server.sh
View file @
a0d23e16
...
...
@@ -58,10 +58,10 @@ while read -r param; do
elif
[[
"
$param_l
"
==
*
"sec-websocket-key:"
*
]]
;
then
r[websocket_key]
=
"
$(
sed
's/Sec-WebSocket-Key: //i;s/\r//'
<<<
"
$param
"
)
"
elif
[[
"
$param_l
"
==
*
"authorization:
B
asic"
*
]]
;
then
elif
[[
"
$param_l
"
==
*
"authorization:
b
asic"
*
]]
;
then
login_simple
"
$param
"
elif
[[
"
$param_l
"
==
*
"authorization:
B
earer"
*
]]
;
then
elif
[[
"
$param_l
"
==
*
"authorization:
b
earer"
*
]]
;
then
r[authorization]
=
"
$(
sed
's/Authorization: Bearer //i;s/\r//'
<<<
"
$param
"
)
"
elif
[[
"
$param_l
"
==
*
"cookie: "
*
]]
;
then
...
...
@@ -73,20 +73,20 @@ while read -r param; do
done
elif [[ "
$param
" == *"
GET
"* ]]; then
r[url]="
$(
echo
-ne
"
$(
sed
-E
's/GET //;s/HTTP\/[0-9]+\.[0-9]+//;s/ //g;s/\
%/\\x/g;s/\
/*\r//g;s/\/\/*/\//g'
<<<
"
$param
"
)
"
)
"
r[url]="
$(
echo
-ne
"
$(
url_decode
"
$(
sed
-E
's/GET //;s/HTTP\/[0-9]+\.[0-9]+//;s/ //g;s/\/*\r//g;s/\/\/*/\//g'
<<<
"
$param
"
)
"
)
"
)
"
data="
$(
echo
${
r
[url]
}
|
sed
-E
's/^(.*)\?//;s/\&/ /g'
)
"
if [[ "
$data
" != "
${
r
[url]
}
" ]]; then
data="
$(
echo
${
r
[url]
}
|
sed
-E
's/^(.*)\?//'
)
"
IFS='&'
for i in
$data
; do
name="
$(
echo
$i
|
sed
-E
's/\=(.*)$//'
)
"
value="
$(
echo
$i
|
sed
"s/
$name
\=
//"
)
"
name="
$(
sed
-E
's/\=(.*)$//'
<<<
"
$i
"
)
"
value="
$(
sed
"s/
$name
\=
//"
<<<
"
$i
"
)
"
get_data[
$name
]="
$value
"
done
fi
elif [[ "
$param
" == *"
POST
"* ]]; then
r[url]="
$(
echo
-ne
"
$(
sed
-E
's/POST //;s/HTTP\/[0-9]+\.[0-9]+//;s/ //g;s/\
%/\\x/g;s/\
/*\r//g;s/\/\/*/\//g'
<<<
"
$param
"
)
"
)
"
r[url]="
$(
echo
-ne
"
$(
url_decode
"
$(
sed
-E
's/POST //;s/HTTP\/[0-9]+\.[0-9]+//;s/ //g;s/\/*\r//g;s/\/\/*/\//g'
<<<
"
$param
"
)
"
)
"
)
"
r[post]=true
# below shamelessly copied from GET, should be moved to a function
data="
$(
sed
-E
's/^(.*)\?//;s/\&/ /g'
<<<
"
${
r
[url]
}
"
)
"
...
...
@@ -94,9 +94,9 @@ while read -r param; do
data="
$(
sed
-E
's/^(.*)\?//'
<<<
"
${
r
[url]
}
"
)
"
IFS='&'
for i in
$data
; do
name="
$(
echo
$i
|
sed
-E
's/\=(.*)$//'
)
"
value="
$(
echo
$i
|
sed
"s/
$name
\=
//"
)
"
ge
t_data[
$name
]="
$value
"
name="
$(
sed
-E
's/\=(.*)$//'
<<<
"
$i
"
)
"
value="
$(
sed
"s/
$name
\=
//"
<<<
"
$i
"
)
"
pos
t_data[
$name
]="
$value
"
done
fi
fi
...
...
Write
Preview
Supports
Markdown
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