Thanks for the patch, but I think it would be preferable to use awk or
sed instead of perl...
Anyways, this is something we ought to fix.
Yes, I agree to you.
I have challenged to write a percent-encoding code without perl.
A patch I have attached is works using sed instead of perl.
(Additionally, seq, printf and tr is used. but these are included in coreutils
package)
I guess that sed have no functionality similar to "pack" in perl.
Therefore, my approach is making pattern like following first:
s/\x00/%00/g
s/\x01/%01/g
s/\x02/%02/g
s/\x03/%03/g
s/\x04/%04/g
...[snip]...
s/\xFC/%FC/g
s/\xFD/%FD/g
s/\xFE/%FE/g
s/\xFF/%FF/g
And then, apply this pattern to string that should be percent-encoded using sed.
I explain shortly about my patch:
The pattern "s/%/%25/g" is placed the top of patterns.
The pattern "s/\x5C/%5C/g" (substitute "\" to %5C) will occurs an error
"Trailing backslash", but I can't find what is wrong.
So I have simply changed it to "s/\\/%5C/g".
The pattern "s/\[/%5B/g" and "s/\^/%5E/g" is same reason.
"1!{s/^/%0A/g}" and "tr -d '\n'" is a workaround for substitute 0x0A ("\n",
newline character) to %0A.
I have confirmed this code is works fine on bash, dash and zsh.
However, this code is longer and complex than code that used perl.
It might be possible to write more smart code, but I have no skill to do it...
regards,
Morita Sho
--- firefox.orig 2006-01-18 12:26:05.000000000 +0900
+++ firefox 2006-01-18 14:11:52.000000000 +0900
@@ -211,9 +211,15 @@
if [ "$?" -ne "0" ] && [ -e "`pwd`/${opt}" ]; then
opt="`pwd`/${opt}"
fi
- # Replace all spaces by %20 and prepend file:// if it is a valid file
+ # Make it percent-encoded and prepend file:// if it is a valid file
if [ -e "${opt}" ]; then
- opt="file://`echo ${opt} | sed 's/ /%20/g'`"
+ pattern="s/%/%25/g;"
+ for i in $(seq 0 31; seq 127 255; echo 32 34 35 59 60 62 63 93 96 123 124 125 ); do
+ pattern="${pattern}$(printf "s/\\\x%02X/%%%02X/g;" $i $i)"
+ done
+ pattern="${pattern}"'s/\[/%5B/g;s/\\/%5C/g;s/\^/%5E/g;'
+ pattern="${pattern}"'1!{s/^/%0A/g};'
+ opt="file://$( echo -n "${opt}" | sed -e "${pattern}" | tr -d '\n' )"
fi
fi
set "$@" "${opt}"