From 962d5e038f5c6406ce2d4d9514d69849c4e00812 Mon Sep 17 00:00:00 2001 From: Willy Tarreau Date: Wed, 20 Nov 2024 08:42:02 +0100 Subject: [PATCH] DOC: configuration: explain the rules regarding spaces in arguments Spaces around commas or parenthesis in expressions are generally part of the value due to the long history of supporting unquoted arguments. But this tends to come as a surprise to new users and sometimes creates subtly invalid configurations. Let's add some text covering this. This can be backported to 2.4. --- doc/configuration.txt | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/doc/configuration.txt b/doc/configuration.txt index b35a2562b7..645ccb3d27 100644 --- a/doc/configuration.txt +++ b/doc/configuration.txt @@ -852,6 +852,26 @@ double quotes inside (so that the double quotes are not stripped again): arg2 ___________/ / arg3 _______________/ +But in this case it's important to note that delimiters embedded into the +higher level string remain pure characters and are not delimiters anymore. It +particularly means that spaces and tabs around commas are part of the string. +The example below is wrong on multiple points: + + http-request set-path '%[path, regsub("(foo|bar)", blah, g)]' + ------------ -------- -------------------------------------- + word1 word2 word3=%[path, regsub("(foo|bar)", blah, g)] + |--------|---------||-----|--| + converter=" regsub" _/ / / / + arg1=(foo|bar) _/ / / + arg2=" blah" ___________/ / + arg3=" g" ______________/ + +The single fact of surrounding commas with spaces resulted in the spaces being +part of the field itself, hence the converter " regsub" (starting with a +space), which won't be found and will trigger an error, but more subtly, the +replacement string " blah" will insert a space in the output. A good rule of +thumb is to never insert unneeded spaces inside expressions. + When using regular expressions, it can happen that the dollar ('$') character appears in the expression or that a backslash ('\') is used in the replacement string. In this case these ones will also be processed inside the double quotes -- 2.47.3