Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Sanitization for the input file for termux-open command #58

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

eternalfrustation
Copy link

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

@agnostic-apollo
Copy link
Member

If you always do encoding, you will break paths if they were already encoded by user before passing to termux-open, so you need to add an -e and --encode option that conditionally does it.

Moreover, it's best not to encode yourself, encoding algorithms are very complex. You can use curl to encode. Add following after if [ -f "$FILE" ] condition.

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/")"
fi

Also commit format must be as per repo git history. Use

termux-open: Add `-e` and `--encode` options to encode characters like `%` in file path

Closes termux/termux-app#3250

Abocram22

This comment was marked as spam.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants