引用和转意

HAProxy's configuration introduces a quoting and escaping system similar to many programming languages. The configuration file supports 3 types: escaping with a backslash, weak quoting with double quotes, and strong quoting with single quotes.

If spaces have to be entered in strings, then they must be escaped by preceding them by a backslash ('\') or by quoting them. Backslashes also have to be escaped by doubling or strong quoting them.

Escaping is achieved by preceding a special character by a backslash ('\'):

  • \ to mark a space and differentiate it from a delimiter
  • \# to mark a hash and differentiate it from a comment
  • \\ to use a backslash
  • \' to use a single quote and differentiate it from strong quoting
  • \" to use a double quote and differentiate it from weak quoting

Weak quoting is achieved by using double quotes (""). Weak quoting prevents the interpretation of:

  • space as a parameter separator
  • ' single quote as a strong quoting delimiter
  • # hash as a comment start

Weak quoting permits the interpretation of variables, if you want to use a non -interpreted dollar within a double quoted string, you should escape it with a backslash ("$"), it does not work outside weak quoting.

Interpretation of escaping and special characters are not prevented by weak quoting.

Strong quoting is achieved by using single quotes (''). Inside single quotes,nothing is interpreted, it's the efficient way to quote regexes.

Quoted and escaped strings are replaced in memory by their interpreted equivalent, it allows you to perform concatenation.

举例:

# those are equivalents:
log-format %{+Q}o\ %t\ %s\ %{-Q}r
log-format "%{+Q}o %t %s %{-Q}r"
log-format '%{+Q}o %t %s %{-Q}r'
log-format "%{+Q}o %t"' %s %{-Q}r'
log-format "%{+Q}o %t"' %s'\ %{-Q}r

# those are equivalents:
reqrep "^([^\ :]*)\ /static/(.*)"     \1\ /\2
reqrep "^([^ :]*)\ /static/(.*)"     '\1 /\2'
reqrep "^([^ :]*)\ /static/(.*)"     "\1 /\2"
reqrep "^([^ :]*)\ /static/(.*)"     "\1\ /\2"

results matching ""

    No results matching ""