I have an irule that parses http payload that contain xml using the findstr function; the problem is some vendors xml requests have spaces and/or newline characters which getting difficult to account for. I am attempting to perform a string map - replacing spaces and newline chars with empty space. I keep getting errors and I cannot seem to get to save without errors.
Here is the actual line - attempting to replace all newline & spaces with empty from the HTTP:payload - while capturing string into the variable
The second string map syntax looks correct and works with tclsh:
% string map [list " " “” “\n” “”] "text with spaces followed by \
a new line"
textwithspacesfollowedbyanewline
I don’t have access to a test box at the moment to try this with findstr. Can you separate the findstr and string map commands with another temporary variable and check whether it is actually the string map or findstr commands generating the syntax error?
If the issue is with the string map command, you could try an alternate syntax:
% string map [list { } {} \n {}] "string with spaces and \
The bottom one applies correctly on 9.x and 10.x, the top one complains about the undefined procedure (the parser -- incorrectly -- thinks that the bracketed syntax should contain some sort of command). In testing this, it appears to work fine, although smacking around a payload in this way is a bit scary to me…
I think wrapping the find/replace token in square braces won’t work as the square brackets act like backticks in *nix and mean the string within is executed as a command.
Hoolio, that’s true enough. It’s interesting, though, that tclsh will let you do it without issues -- I guess converting the brackets to act like curly-braces if there’s no actual command/procedure to execute inside it? Not that it’s the BigIP parser’s fault, really… just an interesting difference in behavior between it and tclsh.
It’s academic, really, as the official TCL documentation for the “string map” command clearly uses curly-braces for search items.