Skip to content

Commit

Permalink
Improve glob handling for folders with (, ), [ or ] in the fi…
Browse files Browse the repository at this point in the history
…le path (#12715)

* sync package-lock.json

* modify `normalizePath` to keep `\\[`, `\\]`, `\\(` and `\\)` into account

* manually escape () and [] characters in globs

* update changelog
  • Loading branch information
RobinMalfait committed Jan 5, 2024
1 parent fbb86a2 commit a5ae318
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- Don't remove keyframe stops when using important utilities ([#12639](https://github.com/tailwindlabs/tailwindcss/pull/12639))
- Don't add spaces to gradients and grid track names when followed by `calc()` ([#12704](https://github.com/tailwindlabs/tailwindcss/pull/12704))
- Improve glob handling for folders with `(`, `)`, `[` or `]` in the file path ([#12715](https://github.com/tailwindlabs/tailwindcss/pull/12715))

### Added

Expand Down
43 changes: 42 additions & 1 deletion src/lib/content.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,48 @@ import fs from 'fs'
import path from 'path'
import isGlob from 'is-glob'
import fastGlob from 'fast-glob'
import normalizePath from 'normalize-path'
import { parseGlob } from '../util/parseGlob'
import { env } from './sharedState'
import { resolveContentPaths } from '@tailwindcss/oxide'

/*!
* Modified version of normalize-path, original license below
*
* normalize-path <https://github.com/jonschlinkert/normalize-path>
*
* Copyright (c) 2014-2018, Jon Schlinkert.
* Released under the MIT License.
*/

function normalizePath(path) {
if (typeof path !== 'string') {
throw new TypeError('expected path to be a string')
}

if (path === '\\' || path === '/') return '/'

var len = path.length
if (len <= 1) return path

// ensure that win32 namespaces has two leading slashes, so that the path is
// handled properly by the win32 version of path.parse() after being normalized
// https://msdn.microsoft.com/library/windows/desktop/aa365247(v=vs.85).aspx#namespaces
var prefix = ''
if (len > 4 && path[3] === '\\') {
var ch = path[2]
if ((ch === '?' || ch === '.') && path.slice(0, 2) === '\\\\') {
path = path.slice(2)
prefix = '//'
}
}

// Modified part: instead of purely splitting on `\\` and `/`, we split on
// `/` and `\\` that is _not_ followed by any of the following characters: ()[]
// This is to ensure that we keep the escaping of brackets and parentheses
let segs = path.split(/[/\\]+(?![\(\)\[\]])/)
return prefix + segs.join('/')
}

/** @typedef {import('../../types/config.js').RawFile} RawFile */
/** @typedef {import('../../types/config.js').FilePath} FilePath */

Expand Down Expand Up @@ -105,6 +142,10 @@ export function parseCandidateFiles(context, tailwindConfig) {
* @returns {ContentPath}
*/
function parseFilePath(filePath, ignore) {
// Escape special characters in the file path such as: ()[]
// But only if the special character isn't already escaped
filePath = filePath.replace(/(?<!\\)([\[\]\(\)])/g, '\\$1')

let contentPath = {
original: filePath,
base: filePath,
Expand Down

0 comments on commit a5ae318

Please sign in to comment.