Added Sanitization for the input file for termux-open command#58
Open
eternalfrustation wants to merge 1 commit intotermux:masterfrom
Open
Added Sanitization for the input file for termux-open command#58eternalfrustation wants to merge 1 commit intotermux:masterfrom
eternalfrustation wants to merge 1 commit intotermux:masterfrom
Conversation
Member
|
If you always do encoding, you will break paths if they were already encoded by user before passing to Moreover, it's best not to encode yourself, encoding algorithms are very complex. You can use if [ "$ENCODE" = "1" ]; then
# Encode FILE with curl. sed replaced trailing newline and the "/?" prefix.
# - https://stackoverflow.com/a/10797966
FILE="$(printf "%s" "$FILE" | { curl -Gs -w %{url_effective} --data-urlencode @- ./ || :; } | sed -e "s/%0[aA]$//; s/^[^?]*?\(.*\)/\1/")"
fiAlso commit format must be as per repo git history. Use |
twaik
requested changes
May 27, 2025
Comment on lines
+44
to
+59
| string="$1" | ||
| length=$(echo "$string" | wc -c) | ||
| length=$((length - 1)) | ||
| encoded="" | ||
|
|
||
| i=1 | ||
| while [ "$i" -le "$length" ]; do | ||
| char=$(echo "$string" | cut -c "$i") | ||
| case "$char" in | ||
| [a-zA-Z0-9.~_-]) encoded="$encoded$char";; | ||
| *) encoded="$encoded%$(printf "%02X" "'$char")";; | ||
| esac | ||
| i=$((i + 1)) | ||
| done | ||
|
|
||
| echo "$encoded" |
Member
There was a problem hiding this comment.
It may be done much easier without invoking external commands lots of times.
Suggested change
| string="$1" | |
| length=$(echo "$string" | wc -c) | |
| length=$((length - 1)) | |
| encoded="" | |
| i=1 | |
| while [ "$i" -le "$length" ]; do | |
| char=$(echo "$string" | cut -c "$i") | |
| case "$char" in | |
| [a-zA-Z0-9.~_-]) encoded="$encoded$char";; | |
| *) encoded="$encoded%$(printf "%02X" "'$char")";; | |
| esac | |
| i=$((i + 1)) | |
| done | |
| echo "$encoded" | |
| for ((i=0; i<${#1}; i++)); do | |
| case "${1:i:1}" in | |
| [a-zA-Z0-9.~_-]) printf '%s' "${1:i:1}" ;; | |
| *) printf '%%%02X' "'${1:i:1}" ;; | |
| esac | |
| done | |
| echo |
Member
There was a problem hiding this comment.
Oh, it is regular /bin/sh, not a bash. Right.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The termux-open command had no sanitization for the input file, which prevented it from opening files containing % characters, this P.R. adds that sanitization.
termux/termux-app#3250