Browse Source

helper for urldecode and encode, some fixes

Jaromil 4 years ago
parent
commit
fca82a9e74
1 changed files with 81 additions and 4 deletions
  1. 81 4
      zuper

+ 81 - 4
zuper

@@ -47,7 +47,7 @@ function _msg() {
47 47
     done
48 48
 
49 49
     local command="print -P"
50
-    local progname="$fg[magenta]${TOMBEXEC##*/}$reset_color"
50
+    local progname="$fg[magenta]${PROGRAM##*/}$reset_color"
51 51
     local message="$fg_bold[normal]$fg_no_bold[normal]$msg$reset_color"
52 52
     local -i returncode
53 53
 
@@ -266,7 +266,7 @@ destruens+=(_ztmp_destructor)
266 266
 # saves everything in global array tok=()
267 267
 arrs+=(tok)
268 268
 strtok() {
269
-    fn "strtok $*"
269
+    fun="strtok $*"
270 270
     _string="$1"
271 271
     _delim="$2"
272 272
     req=(_string _delim)
@@ -546,7 +546,7 @@ EOF
546 546
     function helper.html-strip xml_strip html_strip() { sed 's/<[^>]\+>//g' }
547 547
 
548 548
     # changes stdin string special chars to be shown in html
549
-    function helper.excape-html escape_html() {
549
+    function helper.escape-html escape_html() {
550 550
         sed -e '
551 551
 s/\&/\&amp;/g
552 552
 s/>/\&gt;/g
@@ -555,8 +555,85 @@ s/"/\&quot;/g
555 555
 '
556 556
     }
557 557
 
558
-}
558
+    # escapes special chars in urls
559
+    function helper.decode-url decode_url urldecode() {
560
+        sed -e '
561
+s/%25/%/gi
562
+s/%20/ /gi
563
+s/%09/ /gi
564
+s/%21/!/gi
565
+s/%22/"/gi
566
+s/%23/#/gi
567
+s/%24/\$/gi
568
+s/%26/\&/gi
569
+s/%27/'\''/gi
570
+s/%28/(/gi
571
+s/%29/)/gi
572
+s/%2a/\*/gi
573
+s/%2b/+/gi
574
+s/%2c/,/gi
575
+s/%2d/-/gi
576
+s/%2e/\./gi
577
+s/%2f/\//gi
578
+s/%3a/:/gi
579
+s/%3b/;/gi
580
+s/%3d/=/gi
581
+s/%3e//gi
582
+s/%3f/?/gi
583
+s/%40/@/gi
584
+s/%5b/\[/gi
585
+s/%5c/\\/gi
586
+s/%5d/\]/gi
587
+s/%5e/\^/gi
588
+s/%5f/_/gi
589
+s/%60/`/gi
590
+s/%7b/{/gi
591
+s/%7c/|/gi
592
+s/%7d/}/gi
593
+s/%7e/~/gi
594
+s/%09/      /gi
595
+'
596
+    }
559 597
 
598
+    function helper.encode-url encode_url urlencode() {
599
+        sed -e '
600
+s/%/%25/g
601
+s/ /%20/g
602
+s/ /%09/g
603
+s/!/%21/g
604
+s/"/%22/g
605
+s/#/%23/g
606
+s/\$/%24/g
607
+s/\&/%26/g
608
+s/'\''/%27/g
609
+s/(/%28/g
610
+s/)/%29/g
611
+s/\*/%2a/g
612
+s/+/%2b/g
613
+s/,/%2c/g
614
+s/-/%2d/g
615
+s/\./%2e/g
616
+s/\//%2f/g
617
+s/:/%3a/g
618
+s/;/%3b/g
619
+s//%3e/g
620
+s/?/%3f/g
621
+s/@/%40/g
622
+s/\[/%5b/g
623
+s/\\/%5c/g
624
+s/\]/%5d/g
625
+s/\^/%5e/g
626
+s/_/%5f/g
627
+s/`/%60/g
628
+s/{/%7b/g
629
+s/|/%7c/g
630
+s/}/%7d/g
631
+s/~/%7e/g
632
+s/      /%09/g
633
+'
634
+    }
635
+
636
+}
560 637
 # }}} Helpers
561 638
 
562 639
 # {{{ Config