root/10kz/shell/url-decode.sh

Revision 43, 1.1 kB (checked in by jm3, 2 years ago)
  • set Id property on all text-based files
  • correctly handling the "no keys found" case with link to GPG help page (just a stub at this point)
  • Property svn:executable set to *
  • Property svn:keywords set to Id
Line 
1 #!/bin/sh
2
3 # test urls:
4 s="foo.com?paramone=valueone+value1.1"
5 s="foo.com?paramone=valueone+value1.1&p2=val%20thingy%20more%20more%2Fmore"
6 s="feedmelinks.com/login?bounceToPage=%2Fcategorize%3F%26loggedIn%3Dwasnt%26from%3Dtoolbar%26op%3Dsubmit%26name%3DFlickr%253A%2520Photos%2520tagged%2520with%2520jm3%26url%3Dhttp%253A%2F%2Fwww.flickr.com%2Fphotos%2Ftags%2Fjm3%2Finteresting%2F%26ref%3Dhttp%253A%2F%2Fwww.flickr.com%2Fphotos%2Ftags%2Fjm3%2F%26version%3D0.7"
7 s="google.com/accounts/ServiceLogin?service=mail&passive=true&rm=false&continue=http%3A%2F%2Fmail.google.com%2Fmail%2F%3Fui%3Dhtml%26zy%3Dl&ltmpl=wsad&ltmplcache=2"
8
9 qs=$1
10 is_qs=`echo "$qs" | grep "\?" > /dev/null`
11 if [ $? -ne 0 ]
12 then
13         echo no ? found in qs\; bailing
14         exit 1
15 fi
16
17 s=$qs
18
19 params=`echo $s | sed "s/^.*\?//" | sed "s/&/ /g"`
20 for p in $params
21 do
22         echo $p
23         tokens=`echo $p | sed "s/\+/__SPACE__/g" | sed "s/%\([0-9A-F][0-9A-F]\)/ HEX:\1 /g"`
24
25         for t in $tokens
26         do
27                 echo $t | grep -q HEX:
28                 if [ $? = 0 ]
29                 then
30                         t=`echo $t | sed s/HEX://`
31                         echo `printf "%d" 0x$t` | awk '{printf("%c", $1)}'
32                 else
33                         echo -n `echo $t | sed "s/__SPACE__/ /g"`
34                 fi
35                 done
36                 echo
37                 echo
38
39 done
40
41 exit 0
42
Note: See TracBrowser for help on using the browser.