2.2. Quoting and escaping

  1. HAProxy's configuration introduces a quoting and escaping system similar to
  2. many programming languages. The configuration file supports 3 types: escaping
  3. with a backslash, weak quoting with double quotes, and strong quoting with
  4. single quotes.
  5.  
  6. If spaces have to be entered in strings, then they must be escaped by preceding
  7. them by a backslash ('\') or by quoting them. Backslashes also have to be
  8. escaped by doubling or strong quoting them.
  9.  
  10. Escaping is achieved by preceding a special character by a backslash ('\'):
  11.  
  12. \ to mark a space and differentiate it from a delimiter
  13. \# to mark a hash and differentiate it from a comment
  14. \\ to use a backslash
  15. \' to use a single quote and differentiate it from strong quoting
  16. \" to use a double quote and differentiate it from weak quoting
  17.  
  18. Weak quoting is achieved by using double quotes (""). Weak quoting prevents
  19. the interpretation of:
  20.  
  21. space as a parameter separator
  22. ' single quote as a strong quoting delimiter
  23. # hash as a comment start
  24.  
  25. Weak quoting permits the interpretation of variables, if you want to use a non
  26. -interpreted dollar within a double quoted string, you should escape it with a
  27. backslash ("\$"), it does not work outside weak quoting.
  28.  
  29. Interpretation of escaping and special characters are not prevented by weak
  30. quoting.
  31.  
  32. Strong quoting is achieved by using single quotes (''). Inside single quotes,
  33. nothing is interpreted, it's the efficient way to quote regexes.
  34.  
  35. Quoted and escaped strings are replaced in memory by their interpreted
  36. equivalent, it allows you to perform concatenation.

Example:

  1. # those are equivalents:
  2. log-format %{+Q}o\ %t\ %s\ %{-Q}r
  3. log-format "%{+Q}o %t %s %{-Q}r"
  4. log-format '%{+Q}o %t %s %{-Q}r'
  5. log-format "%{+Q}o %t"' %s %{-Q}r'
  6. log-format "%{+Q}o %t"' %s'\ %{-Q}r
  7. # those are equivalents:
  8. reqrep "^([^\ :]*)\ /static/(.*)" \1\ /\2
  9. reqrep "^([^ :]*)\ /static/(.*)" '\1 /\2'
  10. reqrep "^([^ :]*)\ /static/(.*)" "\1 /\2"
  11. reqrep "^([^ :]*)\ /static/(.*)" "\1\ /\2"