]> git.ipfire.org Git - thirdparty/haproxy.git/commit
MEDIUM: samples: add a regsub converter to perform regex-based transformations
authorWilly Tarreau <w@1wt.eu>
Tue, 20 Jan 2015 18:47:06 +0000 (19:47 +0100)
committerWilly Tarreau <w@1wt.eu>
Thu, 22 Jan 2015 13:24:53 +0000 (14:24 +0100)
commit7eda849dce7b93cda5ccf703edaed59b5e28b8bd
tree605a64789378fdd19518d7a184b9c33414c2c184
parent15a53a43846e25c99e37f210ec84349d3ea1c64d
MEDIUM: samples: add a regsub converter to perform regex-based transformations

We can now replace matching regex parts with a string, a la sed. Note
that there are at least 3 different behaviours for existing sed
implementations when matching 0-length strings. Here is the result
of the following operation on each implementationt tested :

  echo 'xzxyz' | sed -e 's/x*y*/A/g'

  GNU sed 4.2.1       => AzAzA
  Perl's sed 5.16.1   => AAzAAzA
  Busybox v1.11.2 sed => AzAz

The psed behaviour was adopted because it causes the least exceptions
in the code and seems logical from a certain perspective :

  - "x"  matches x*y*  => add "A" and skip "x"
  - "z"  matches x*y*  => add "A" and keep "z", not part of the match
  - "xy" matches x*y*  => add "A" and skip "xy"
  - "z"  matches x*y*  => add "A" and keep "z", not part of the match
  - ""   matches x*y*  => add "A" and stop here

Anyway, given the incompatibilities between implementations, it's unlikely
that some processing will rely on this behaviour.

There currently is one big limitation : the configuration parser makes it
impossible to pass commas or closing parenthesis (or even closing brackets
in log formats). But that's still quite usable to replace certain characters
or character sequences. It will become more complete once the config parser
is reworked.
doc/configuration.txt
src/sample.c