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
911eca71
Commit
911eca71
authored
Jun 23, 2021
by
Lauren N. Liberda
Browse files
html_encode: support for data from stdin
parent
c73b8910
Pipeline
#423
failed with stage
in 51 seconds
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
src/misc.sh
View file @
911eca71
...
...
@@ -39,7 +39,11 @@ 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
"
if
[[
"
$1
"
==
""
]]
;
then
sed
's/\&/\&/g;s/</\</g;s/>/\>/g;s/%/\%/g;s/\//\//g;s/\\/\\/g;s/'
"'"
'/\'/g;s/"/\"/g;s/`/\`/g;s/?/\?/g;'
else
sed
's/\&/\&/g;s/</\</g;s/>/\>/g;s/%/\%/g;s/\//\//g;s/\\/\\/g;s/'
"'"
'/\'/g;s/"/\"/g;s/`/\`/g;s/?/\?/g;'
<<<
"
$1
"
fi
}
# url_encode(string)
...
...
src/template.sh
View file @
911eca71
...
...
@@ -7,8 +7,12 @@ function render() {
local
-n
ref
=
$1
local
tmp
=
$(
mktemp
)
for
key
in
${
!ref[@]
}
;
do
local
value
=
"
$(
html_encode
"
${
ref
[
$key
]
}
"
|
sed
-E
's/\&/�UwU�/g'
)
"
echo
's/\{\{\.'
"
$key
"
'\}\}/'
"
$value
"
'/g'
>>
"
$tmp
"
if
[[
"
${
ref
[
$key
]
}
"
!=
""
]]
;
then
local
value
=
"
$(
html_encode
"
${
ref
[
$key
]
}
"
|
sed
-E
's/\&/�UwU�/g'
)
"
echo
's/\{\{\.'
"
$key
"
'\}\}/'
"
$value
"
'/g'
>>
"
$tmp
"
else
echo
's/\{\{\.'
"
$key
"
'\}\}//g'
>>
"
$tmp
"
fi
done
template
=
"
$(
sed
-E
-f
"
$tmp
"
<<<
"
$template
"
)
"
sed
-E
's/�UwU�/\&/g'
<<<
"
$template
"
...
...
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