Skip to content

Convert back backslash escapes to carets in Win32

Francesco Pretto requested to merge ceztko/kwsys:fix-escape-quotes-win32 into master

This fixes issue 17412[1] in CMake. Currently kwsys seems to assume \ character is a valid escape character in Windows scripting. According to various sources[2][3], this is not correct. The current change assumes \ and ^ are both correct escape characters as an input to kwsys Win32 code, converting back backslashes to carets if needed. This seems a decent behavior at least in CMake, which similarly to path separator slash / (which is supported almost universally anyway in Win32) it may treat \ as the common way to specify an escape character. Since there is no bug tracker for kwsys, and I'm not confident this is the best fix, I open this merge request as a place for discussions. Also I don't know the kwsys project and I'm not aware of existing test suites meaning I don't know if this change may break other users.

It may be relevant to discuss why kwsys is escaping quotes " at all. With the current change cmd /c dir \"C:/\" is converted back to cmd /c dir ^"C:/^" before execution which is correctly processed by batch (or any command prompt), but also cmd /c dir "C:/" would be processed correctly as well.

[1] cmake/cmake#17412 (closed)

[2] https://blogs.msdn.microsoft.com/oldnewthing/20080806-01/?p=21343

[3] https://stackoverflow.com/a/562080/213871

Merge request reports