Skip to content

Instantly share code, notes, and snippets.

@facugon
Last active October 19, 2018 20:21
Show Gist options
  • Save facugon/c4c16b1c5ed21345eec3e2eb1dfb0044 to your computer and use it in GitHub Desktop.
Save facugon/c4c16b1c5ed21345eec3e2eb1dfb0044 to your computer and use it in GitHub Desktop.
URL Encode Alternatives
title="something horrible!"
encodedtitle=`echo "$title" | jq -s -R -r @uri`
# need to install URI::Escape
#perl -MURI::Escape -e 1
#if [ $? != 0 ];
#then
# echo "installing dependencies"
# PERL_MM_USE_DEFAULT=1 perl -MCPAN -e 'install URI::Escape'
#fi
encodedtitle=`perl -MURI::Escape -e 'print uri_escape($ARGV[0]);' "$title"`
encodedtitle=`python -c "import sys, urllib as ul; print ul.quote_plus(sys.argv[1])" $title`
@facugon
Copy link
Author

facugon commented Oct 19, 2018

to encode a value that will be used in a URL , for example

http://domain/resouce/to/fetch/with/title/$title

when title is a horrible thing

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment