1#!/usr/bin/env bash 2# Copyright © 2013 Christian Persch 3# Copyright © 2019 Red Hat, Inc. 4# 5# This program is free software: you can redistribute it and/or modify 6# it under the terms of the GNU General Public License as published by 7# the Free Software Foundation, either version 3 of the License, or 8# (at your option) any later version. 9# 10# This program is distributed in the hope that it will be useful, 11# but WITHOUT ANY WARRANTY; without even the implied warranty of 12# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13# GNU General Public License for more details. 14# 15# You should have received a copy of the GNU General Public License 16# along with this program. If not, see <https://www.gnu.org/licenses/>. 17# 18# Red Hat Author(s): Carlos Santos 19 20set -e 21 22vte_urlencode_cwd="$1" 23 24test -x "$vte_urlencode_cwd" || exit 126 25 26export PWD 27 28check_urlencode() { 29 PWD=$(echo -ne "$1") 30 encoded=$("$vte_urlencode_cwd") 31 if test "$encoded" != "$2"; then 32 echo "FAILED:" 33 echo "Input : \"$PWD\"" 34 echo "Output : \"$encoded\"" 35 echo "Expected: \"$2\"" 36 fi 37} 38 39# raw bytes 40 41check_urlencode "\001\002\003\004\005\006\007\010\011\012\013\014\015\016\017" \ 42 "%01%02%03%04%05%06%07%08%09%0A%0B%0C%0D%0E%0F" 43check_urlencode "\020\021\022\023\024\025\026\027\030\031\032\033\034\035\036\037" \ 44 "%10%11%12%13%14%15%16%17%18%19%1A%1B%1C%1D%1E%1F" 45check_urlencode "\040\041\042\043\044\045\046\047\050\051\052\053\054\055\056\057" \ 46 "%20!%22%23%24%25%26'()%2A%2B%2C-./" 47check_urlencode "\060\061\062\063\064\065\066\067\070\071\072\073\074\075\076\077" \ 48 "0123456789:%3B%3C%3D%3E%3F" 49check_urlencode "\0100\0101\0102\0103\0104\0105\0106\0107\0110\0111\0112\0113\0114\0115\0116\0117" \ 50 "%40ABCDEFGHIJKLMNO" 51check_urlencode "\0120\0121\0122\0123\0124\0125\0126\0127\0130\0131\0132\0133\0134\0135\0136\0137" \ 52 "PQRSTUVWXYZ%5B%5C%5D%5E_" 53check_urlencode "\0140\0141\0142\0143\0144\0145\0146\0147\0150\0151\0152\0153\0154\0155\0156\0157" \ 54 "%60abcdefghijklmno" 55check_urlencode "\0160\0161\0162\0163\0164\0165\0166\0167\0170\0171\0172\0173\0174\0175\0176\0177" \ 56 "pqrstuvwxyz%7B%7C%7D~%7F" 57check_urlencode "\0200\0201\0202\0203\0204\0205\0206\0207\0210\0211\0212\0213\0214\0215\0216\0217" \ 58 "%80%81%82%83%84%85%86%87%88%89%8A%8B%8C%8D%8E%8F" 59check_urlencode "\0220\0221\0222\0223\0224\0225\0226\0227\0230\0231\0232\0233\0234\0235\0236\0237" \ 60 "%90%91%92%93%94%95%96%97%98%99%9A%9B%9C%9D%9E%9F" 61check_urlencode "\0240\0241\0242\0243\0244\0245\0246\0247\0250\0251\0252\0253\0254\0255\0256\0257" \ 62 "%A0%A1%A2%A3%A4%A5%A6%A7%A8%A9%AA%AB%AC%AD%AE%AF" 63check_urlencode "\0260\0261\0262\0263\0264\0265\0266\0267\0270\0271\0272\0273\0274\0275\0276\0277" \ 64 "%B0%B1%B2%B3%B4%B5%B6%B7%B8%B9%BA%BB%BC%BD%BE%BF" 65check_urlencode "\0300\0301\0302\0303\0304\0305\0306\0307\0310\0311\0312\0313\0314\0315\0316\0317" \ 66 "%C0%C1%C2%C3%C4%C5%C6%C7%C8%C9%CA%CB%CC%CD%CE%CF" 67check_urlencode "\0320\0321\0322\0323\0324\0325\0326\0327\0330\0331\0332\0333\0334\0335\0336\0337" \ 68 "%D0%D1%D2%D3%D4%D5%D6%D7%D8%D9%DA%DB%DC%DD%DE%DF" 69check_urlencode "\0340\0341\0342\0343\0344\0345\0346\0347\0350\0351\0352\0353\0354\0355\0356\0357" \ 70 "%E0%E1%E2%E3%E4%E5%E6%E7%E8%E9%EA%EB%EC%ED%EE%EF" 71check_urlencode "\0360\0361\0362\0363\0364\0365\0366\0367\0370\0371\0372\0373\0374\0375\0376\0377" \ 72 "%F0%F1%F2%F3%F4%F5%F6%F7%F8%F9%FA%FB%FC%FD%FE%FF" 73 74# UTF-8 75 76check_urlencode "ẞ" "%E1%BA%9E" 77 78# all tests pass! 79exit 0 80