ams-tschoening commented on a change in pull request #83:
URL: https://github.com/apache/logging-log4cxx/pull/83#discussion_r769845917
##########
File path: src/test/cpp/util/transformer.cpp
##########
@@ -116,14 +116,29 @@ void Transformer::createSedCommandFile(const std::string&
regexName,
std::string tmp;
+ auto sedSanitizer = [] (const std::string& in, const std::string&
sedSeparator = "Q")
+ {
+ std::string ret = in;
+ std::string replaceTo = "\\" + sedSeparator;
+ size_t pos = 0;
+
+ while((pos = ret.find(sedSeparator, pos)) != std::string::npos)
+ {
+ ret.replace(pos, sedSeparator.length(), replaceTo);
+ pos += replaceTo.length();
+ }
+
+ return ret;
+ };
+
for (log4cxx::Filter::PatternList::const_iterator iter =
patterns.begin();
iter != patterns.end();
iter++)
{
tmp = "sQ";
Review comment:
For my own thoughts: This results in something like `sQ...Q...Qg`, which
is pretty much the same like `s/.../.../g` or `s!...!...!g` or `s#...#...#g`
etc. The important point is that at least the delimiter needs to be escaped
when available in the input, like was the case for this PR.
OTOH, in theory each and every character would need to be escaped because it
might have special reg exp meaning? SED documents things like `&` and `\1`
already. Though, might not be that important in this context, as it's only
about tests with the only variable input being some paths in the file system.
Modern versions of SED support the argument `--regexp-extended`, which
should support `\Q...\E` to escape arbitrary input. So something like
`sQ\Q...\EQ\Q...\EQg` should work in the future as well.
https://www.boost.org/doc/libs/1_50_0/libs/regex/doc/html/boost_regex/syntax/basic_extended.html#boost_regex.syntax.basic_extended.quoting_escape
Though, a different delimiter should be chosen than to keep things readable.
But on my system I have a version of SED using `UnxUtils` for Windows which
doesn't support that. Instead, I would need to use SED bundled with GIT, but
sadly wasn't able to get that work as expected as well. So am simply keeping
things as they are right now.
> C:\Program Files (x86)\UnxUtils\usr\local\wbin
vs.
> C:\Program Files\Git\usr\bin
[ghpr_83_full_escape.diff.txt](https://github.com/apache/logging-log4cxx/files/7721553/ghpr_83_full_escape.diff.txt)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]