tailwindcss icon indicating copy to clipboard operation
tailwindcss copied to clipboard

Improve Windows support for escaped glob syntax

Open RobinMalfait opened this issue 4 months ago • 2 comments

This PR is a continuation of #12715 to apply the same improvements for Windows.

On Windows the path separator is \\ and \\ is also used for escaping the [, ], ( and ) characters. This will result in \\\\[ for example. In this case it means that the first \\ is the path separator and the second \\ is the escape for the [ or ( characters.

Additionally, we also ensure that we only escape [, ] and (, ) when the balanced pairs are both not escaped yet. Right now it was going over the individual characters and escaping them accordingly.

This is not enough, because in case of this path:

let path = ".\\src\\**\\[foo]\\bar.html"

The first \\[ looks like it is escaped, but on Windows this is just the path separator. The foo] part is not escaped therefor we should escape the whole thing. As a first step, this will result in:

let path = ".\\src\\**\\\\[foo\\]\\bar.html"

Now we do have the 4 backslashes \\\\, then in the normalization step, we normalize \\ to /. If we do this as is, then it would look like this, which is also incorrect:

let path = "./src/**/[foo/]/bar.html"

... it's incorrect because we have /[foo/] and we expected /\\[foo\\] instead.

If we apply the logic I mentioned earlier where the first \\ is the path separator and the second \\ is the escape, then we can convert:

let path = ".\\src\\**\\\\[foo\\]\\bar.html"

... to this first:

let path = ".\\src\\**/\\[foo\\]\\bar.html"

Then we can apply the rest of the normalization, which looks like this:

let path = "./src/**/\\[foo\\]/bar.html"

... and now the [foo] part is properly escaped as \\[foo\\].

RobinMalfait avatar Jan 05 '24 17:01 RobinMalfait

please merge this PR soon as its absolutely essential.

mominshaikhdevs avatar Jan 06 '24 18:01 mominshaikhdevs

It is unfortunately not finished as it doesn't work 100% yet on Windows after I did some testing on Friday.

thecrypticace avatar Jan 07 '24 17:01 thecrypticace

Going to close this PR for now because the original issue that was reported was for macOS / Linux. This is probably still a good fix to do, but the current implementation is not ideal just because an escaped \\ also happens to be a path separator in Windows which means that this is ambiguous.

The real fix should be to split the base path and the actual glob so that the ambiguity goes away. Because then the path can contain \\ as the separator and the glob itself containing \\ will be a guaranteed escape value.

RobinMalfait avatar Mar 21 '24 13:03 RobinMalfait