nodejs / nodejs/node

`path.escapeGlob`

Open
#61,258 2 comments 3 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

feature request
Dominant language
JavaScript
Stars
122k
Forks
37.3k
Avg merge
4d 2h
Merged PRs (30d)
283

Description

What is the problem this feature will solve?

Would allow to dynamically create glob patterns from arbitrary paths.

Example:

const pattern = `${path.escapeGlob(import.meta.dirname)}/*`;
What is the feature you are proposing to solve the problem?

Something similar in functionality to this:

// Wraps symbols which open groups `{`, `[`, `(`, and
// those with semantics independent of groups `*`, `?`
path.escapeGlob = (x = "") => x.replace(/[*{[(?]/g, "[$&]");

And this:

// inverse path.escapeGlob
path.unescapeGlob = (x = "") => x.replace(/\[.\]/g, "$&");

I was using #58988 as a reference for special chars.

What alternatives have you considered?

Using a user land package everywhere dynamic glob creation is required, or even for everything glob related to keep things consistent.

Edit: Shortened regex replacement from (...) -> $1 to ... -> $&.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reading issue #58988 and the existing path API documentation and tests to understand the special characters and platform behavior already covered. Compare the proposed escaping and unescaping semantics across arbitrary paths; done requires an agreed API contract with matching implementation, tests, and documentation.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
api
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.