Skip to content

Commit f2a7c2c

Browse files
RobinMalfaitKrisBraun
authored andcommitted
Improve glob handling for folders with (, ), [ or ] in the file path (#12715)
* sync package-lock.json * modify `normalizePath` to keep `\\[`, `\\]`, `\\(` and `\\)` into account * manually escape () and [] characters in globs * update changelog
1 parent 89f0f54 commit f2a7c2c

File tree

2 files changed

+43
-1
lines changed

2 files changed

+43
-1
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2020
- Don't remove keyframe stops when using important utilities ([#12639](https://github.com/tailwindlabs/tailwindcss/pull/12639))
2121
- Don't add spaces to gradients and grid track names when followed by `calc()` ([#12704](https://github.com/tailwindlabs/tailwindcss/pull/12704))
2222
- Restore old behavior for `class` dark mode strategy ([#12717](https://github.com/tailwindlabs/tailwindcss/pull/12717))
23+
- Improve glob handling for folders with `(`, `)`, `[` or `]` in the file path ([#12715](https://github.com/tailwindlabs/tailwindcss/pull/12715))
2324

2425
### Added
2526

src/lib/content.js

+42-1
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,47 @@ import fs from 'fs'
44
import path from 'path'
55
import isGlob from 'is-glob'
66
import fastGlob from 'fast-glob'
7-
import normalizePath from 'normalize-path'
87
import { parseGlob } from '../util/parseGlob'
98
import { env } from './sharedState'
109

10+
/*!
11+
* Modified version of normalize-path, original license below
12+
*
13+
* normalize-path <https://github.com/jonschlinkert/normalize-path>
14+
*
15+
* Copyright (c) 2014-2018, Jon Schlinkert.
16+
* Released under the MIT License.
17+
*/
18+
19+
function normalizePath(path) {
20+
if (typeof path !== 'string') {
21+
throw new TypeError('expected path to be a string')
22+
}
23+
24+
if (path === '\\' || path === '/') return '/'
25+
26+
var len = path.length
27+
if (len <= 1) return path
28+
29+
// ensure that win32 namespaces has two leading slashes, so that the path is
30+
// handled properly by the win32 version of path.parse() after being normalized
31+
// https://msdn.microsoft.com/library/windows/desktop/aa365247(v=vs.85).aspx#namespaces
32+
var prefix = ''
33+
if (len > 4 && path[3] === '\\') {
34+
var ch = path[2]
35+
if ((ch === '?' || ch === '.') && path.slice(0, 2) === '\\\\') {
36+
path = path.slice(2)
37+
prefix = '//'
38+
}
39+
}
40+
41+
// Modified part: instead of purely splitting on `\\` and `/`, we split on
42+
// `/` and `\\` that is _not_ followed by any of the following characters: ()[]
43+
// This is to ensure that we keep the escaping of brackets and parentheses
44+
let segs = path.split(/[/\\]+(?![\(\)\[\]])/)
45+
return prefix + segs.join('/')
46+
}
47+
1148
/** @typedef {import('../../types/config.js').RawFile} RawFile */
1249
/** @typedef {import('../../types/config.js').FilePath} FilePath */
1350

@@ -73,6 +110,10 @@ export function parseCandidateFiles(context, tailwindConfig) {
73110
* @returns {ContentPath}
74111
*/
75112
function parseFilePath(filePath, ignore) {
113+
// Escape special characters in the file path such as: ()[]
114+
// But only if the special character isn't already escaped
115+
filePath = filePath.replace(/(?<!\\)([\[\]\(\)])/g, '\\$1')
116+
76117
let contentPath = {
77118
original: filePath,
78119
base: filePath,

0 commit comments

Comments
 (0)