Forum Discussion
TCL encoding command not accepted
I need to encode variable with unicode
set uni_msg [URI::query [HTTP::uri] "msg"] set en_msg [encoding convertto unicode $uni_msg]
Seems that F5 interpreter not accepting encoding TCL command, Any hack for this ?
12 Replies
- Hannes_Rapp
Nimbostratus
To correct myself, here's a conversion to unicode. Any UNIX machines default to UTF-8 handling of unicode, that's the format you'll get with this iRule. Note that Windows handles unicode as UTF-16, and you may need to adjust it.
when HTTP_REQUEST { binary scan [HTTP::uri] H* myvar log local0. "TEST: Original URI [HTTP::uri] | UTF-8 unicode $myvar" } Jan 15 16:26:20 waf12 info tmm7[13448]: Rule /Common/test_encode : TEST: Original URI /helloworld?asd=1 | UTF-8 unicode 2f68656c6c6f776f726c643f6173643d31
It results the same in this text to UTF-8 converter tool: http://macchiato.com/unicode/convert.html
- ims_243721
Nimbostratus
URI::encode will result unicode ?
- Hannes_Rapp
Nimbostratus
No sorry, it's for percent encoding. Didn't pay attention to your question :( - Hannes_Rapp
Nimbostratus
I've modified my answer, I believe this is what you're looking for. Good luck :)
- ims_243721
Nimbostratus
its percent encoding , https://en.wikipedia.org/wiki/Percent-encoding
Hi Ims,
unfortunately there does not exist a simple hack to access the
command.[encoding]
In v9 the
command was official listed as a disabled command. In newer versions is not listed anymore... But instead its now completely removed / hidden from the iRule environment, since you can even find the command using[encoding]
. I duno if this is a just documentation bug or an unintended behavior. But you may raise a ticket to clarify the situation with the F5 support.[info command *]
https://support.f5.com/kb/en-us/solutions/public/6000/300/sol6319.html
You may also want to perform the needed unicode conversation using a
command and a[string map]
of your choice. This technique would allow you to define the unicode format and possible escape sequences as required by your application.$charmap
If you need further assistence to setup the charmap, then provide a sample of the unicode format the application expects.
Cheers, Kai
- ims_243721
Nimbostratus
@kai thanks for your support, below example of my array
$unicodeArray[1] = "0x13"; $chrArray[6] = "a"; $unicodeArray[2] = "0x14"; $chrArray[7] = "b"; $unicodeArray[3] = "0x25"; $chrArray[8] = "c"; $unicodeArray[4] = "0x26"; $chrArray[9] = "d";
Hi Ims,
An input string of "abcd" would then become converted to the string "0x13 0x14 0x25 0x26"? Or is the output formated otherwise?
Cheers, Kai
- ims_243721
Nimbostratus
Its input as you mentioned at the first portion
I didnt get the point how the input string and final outcome should look like. Make a very precise example please.
Cheers, Kai
- ims_243721
Nimbostratus
input == >> abcd , output ==> 0x13 0x14 0x25 0x26
Hi Ims,
the custom char map would then look like this...
Example1:
when HTTP_REQUEST { set uri_input "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" set input [URI::decode $uri_input] set output [string trim [string map { "a" " 0x13" "b" " 0x14" "c" " 0x25" "d" " 0x26" "e" " 0x13" "f" " 0x14" "g" " 0x25" "h" " 0x26" "i" " 0x13" "j" " 0x14" "k" " 0x25" "l" " 0x26" "m" " 0x13" "n" " 0x14" "o" " 0x25" "p" " 0x26" "q" " 0x13" "r" " 0x14" "s" " 0x25" "t" " 0x26" "u" " 0x13" "v" " 0x14" "w" " 0x25" "x" " 0x26" "y" " 0x13" "z" " 0x14" "A" " 0x13" "B" " 0x14" "C" " 0x25" "D" " 0x26" "E" " 0x13" "F" " 0x14" "G" " 0x25" "H" " 0x26" "I" " 0x13" "J" " 0x14" "K" " 0x25" "L" " 0x26" "M" " 0x13" "N" " 0x14" "O" " 0x25" "P" " 0x26" "Q" " 0x13" "R" " 0x14" "S" " 0x25" "T" " 0x26" "U" " 0x13" "V" " 0x14" "W" " 0x25" "X" " 0x26" "Y" " 0x13" "Z" " 0x14" } $input ]] }
If this technique clutters your code too much, then you could also outsource the functionality into a TCL procedure. But it would cause some added overhead for the procedure housekeeping...
Example2:
when HTTP_REQUEST { set uri_input "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" set input [URI::decode $uri_input] set output [call YOUR_RULE_NAME::MY_CHAR_MAP $input] } proc MY_CHAR_MAP { string } { return [string trim [string map { "a" " 0x13" "b" " 0x14" "c" " 0x25" "d" " 0x26" "e" " 0x13" "f" " 0x14" "g" " 0x25" "h" " 0x26" "i" " 0x13" "j" " 0x14" "k" " 0x25" "l" " 0x26" "m" " 0x13" "n" " 0x14" "o" " 0x25" "p" " 0x26" "q" " 0x13" "r" " 0x14" "s" " 0x25" "t" " 0x26" "u" " 0x13" "v" " 0x14" "w" " 0x25" "x" " 0x26" "y" " 0x13" "z" " 0x14" "A" " 0x13" "B" " 0x14" "C" " 0x25" "D" " 0x26" "E" " 0x13" "F" " 0x14" "G" " 0x25" "H" " 0x26" "I" " 0x13" "J" " 0x14" "K" " 0x25" "L" " 0x26" "M" " 0x13" "N" " 0x14" "O" " 0x25" "P" " 0x26" "Q" " 0x13" "R" " 0x14" "S" " 0x25" "T" " 0x26" "U" " 0x13" "V" " 0x14" "W" " 0x25" "X" " 0x26" "Y" " 0x13" "Z" " 0x14" } $string ]] }
Cheers, Kai
Recent Discussions
Related Content
* Getting Started on DevCentral
* Community Guidelines
* Community Terms of Use / EULA
* Community Ranking Explained
* Community Resources
* Contact the DevCentral Team
* Update MFA on account.f5.com