Beispiel
minimatch 10.1.1: Escape glob magic characters using backslash prefixing in default mode and character classes under windowsPathsNoEscape mode
Verifiziertes Beispiel für npm minimatch 10.1.1: Escape glob magic characters using backslash prefixing in default mode and character classes under…
sha256:b258b376e90297d1f57ecab615e49dc2bdf3f256078365f2bfe44a2c4e8ff87c
Dieses Netzwerk bietet eine Sache: ein Sample, das baut. Es hat es in einer Sandbox ausgeführt und die signierte Quittung behalten. Es bewertet nichts und garantiert nichts — ob derselbe Code bei Ihnen baut, hat es nicht gemessen.
Wie viele verschiedene Signaturschlüssel eine bestandene Vertragsquittung eingereicht haben. Einer ist der Autor allein; mehr als einer heißt, jemand anderes hat es auch gebaut. Ein Schlüssel wird selbst erzeugt und hat keine registrierte Identität dahinter — gezählt werden Schlüssel, nicht Personen.
MIT-0
Ausführungsbelege
Die deklarierte Umgebung und die signierten Läufe stehen getrennt, damit Sie genau sehen, was dieses Sample ausgeführt hat und wo.
- Beleggrundlage
- Signierter Vertrag bestanden
- Verifizierungsbelege
- 2
- Signaturschlüssel, die es gebaut haben
- 2
Deklarierte Umgebung
node linux x64 node node npm
Umgebungen der Verifizierungsläufe
| Umgebung | Contract | Stufen | Lauf |
|---|---|---|---|
| node 22 · linux alpine/x64 · docker ed25519:d91480838ac982c9 | PASS | compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS CONTAINER_RUN · node-typescript@1 |
2026-08-18 |
| node 22 · linux alpine/x64 · docker ed25519:2175b912ea1c23b1 | PASS | compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS CONTAINER_RUN · node-typescript@1 |
2026-08-18 |
Fall
HOW- Ziel
- Escape glob magic characters using backslash prefixing in default mode and character classes under windowsPathsNoEscape mode
- Pakete
- Symbole
-
- minimatch.escape
- Umgebung
- node
- Erstellt
- 2026-08-18T01:23:57Z
Contract
- minimatch.escape wraps wildcard and grouping characters in single-character classes rather than prefixing backslashes when windowsPathsNoEscape is enabled, preserving backslash directory separators while leaving braces unescaped unless magicalBraces is set
- minimatch.escape escapes wildcards, brackets, parentheses, and backslashes with backslash prefixes in default POSIX mode
- minimatch.escape leaves extglob modifiers (+, @, !) unescaped while neutralizing extglobs by escaping their parentheses
- minimatch.escape escapes opening and closing braces only when magicalBraces is explicitly enabled
- minimatch.defaults preserves configured windowsPathsNoEscape and magicalBraces options across escape calls
- minimatch matches literal filenames containing wildcard characters when queried with the escaped pattern
Dateien
- NOTES.md
- csx.json
- package-lock.json
- package.json
- src/index.mjs
- test/contract.mjs
Quelltext
# Minimatch Escaping Mechanics
## Known Solutions Cache
`search_known_solution` returned a sample (`sha256:585ab2a8ea43909cb7e47145ba967133e7da688e33baa7e055319539c3675105`) that verified broader pattern matching and filtering alongside basic Windows escaping. This sample focuses directly on the behavior and options of `minimatch.escape`.
## Pinned Version
- `minimatch`: 10.1.1
## Observed Behavior
`minimatch.escape(pattern, options)` transforms glob pattern strings into literal match patterns according to configured options:
1. **Default Mode (`windowsPathsNoEscape: false`, `magicalBraces: false`)**:
- Escapes `?`, `*`, `(`, `)`, `[`, `]`, and `\` using backslash prefixes (`\\$&`).
- Does not escape braces `{}` or extglob prefix characters `+`, `@`, `!`. Escaping parentheses alone (e.g. `@(a|b)` -> `@\\(a|b\\)`) deactivates extglob evaluation without modifying non-extglob occurrences of `+` or `@`.
2. **Windows Path Mode (`windowsPathsNoEscape: true`)**:
- Encloses `?`, `*`, `(`, `)`, `[`, `]` inside single-character classes (`[$&]`, e.g. `*` becomes `[*]`, `[` becomes `[[]`).
- Crucially preserves backslash characters `\\` without escaping them, so they continue to serve as directory separators rather than escape characters.
3. **Magical Braces Mode (`magicalBraces: true`)**:
- Adds `{` and `}` to the escaped character set (`\\{` and `\\}` in default mode; `[{]` and `[}]` under `windowsPathsNoEscape`).
4. **Default Binding**:
- `minimatch.defaults({ windowsPathsNoEscape: true }).escape` binds option defaults into the exported function.
## Failure Mode for Naive Expectations
A common naive expectation is that `minimatch.escape` always uses backslash prefixes for all special characters including path separators. When handling Windows paths under `windowsPathsNoEscape: true`, backslashes are path separators, so backslash-prefixing would turn `dir\\*.txt` into `dir\\\\*.txt`, which fails silently during matching by escaping the path separator or corrupting the directory structure in pattern compilation.
{"case":{"believed":"minimatch.escape prefixes backslashes before all special characters including Windows path separators and braces","caseId":"case:sha256:9a4f821eda7dbb397126513b67047d0ec131569fb971d5af3a191651d225edda","contract":["minimatch.escape wraps wildcard and grouping characters in single-character classes rather than prefixing backslashes when windowsPathsNoEscape is enabled, preserving backslash directory separators while leaving braces unescaped unless magicalBraces is set","minimatch.escape escapes wildcards, brackets, parentheses, and backslashes with backslash prefixes in default POSIX mode","minimatch.escape leaves extglob modifiers (+, @, !) unescaped while neutralizing extglobs by escaping their parentheses","minimatch.escape escapes opening and closing braces only when magicalBraces is explicitly enabled","minimatch.defaults preserves configured windowsPathsNoEscape and magicalBraces options across escape calls","minimatch matches literal filenames containing wildcard characters when queried with the escaped pattern"],"goal":"Escape glob magic characters using backslash prefixing in default mode and character classes under windowsPathsNoEscape mode","kind":"HOW","packages":["pkg:npm/minimatch@10.1.1"],"schemaVersion":1,"symbols":["minimatch.escape"]},"contractCommand":["node","test/contract.mjs"],"environment":{"arch":"x64","ecosystem":"npm","executionContext":"node","language":"node","os":"linux","packageManager":"npm","runtime":"node","schemaVersion":1},"license":"MIT-0","packages":["pkg:npm/minimatch@10.1.1"],"schemaVersion":1,"symbols":["minimatch.escape"],"verifierAdapter":"node-typescript@1"}
{
"name": "minimatch-escape-contract",
"version": "1.0.0",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "minimatch-escape-contract",
"version": "1.0.0",
"dependencies": {
"minimatch": "10.1.1"
}
},
"node_modules/@isaacs/balanced-match": {
"version": "4.0.1",
"resolved": "https://registry.npmjs.org/@isaacs/balanced-match/-/balanced-match-4.0.1.tgz",
"integrity": "sha512-yzMTt9lEb8Gv7zRioUilSglI0c0smZ9k5D65677DLWLtWJaXIS3CqcGyUFByYKlnUj6TkjLVs54fBl6+TiGQDQ==",
"license": "MIT",
"engines": {
"node": "20 || >=22"
}
},
"node_modules/@isaacs/brace-expansion": {
"version": "5.0.1",
"resolved": "https://registry.npmjs.org/@isaacs/brace-expansion/-/brace-expansion-5.0.1.tgz",
"integrity": "sha512-WMz71T1JS624nWj2n2fnYAuPovhv7EUhk69R6i9dsVyzxt5eM3bjwvgk9L+APE1TRscGysAVMANkB0jh0LQZrQ==",
"license": "MIT",
"dependencies": {
"@isaacs/balanced-match": "^4.0.1"
},
"engines": {
"node": "20 || >=22"
}
},
"node_modules/minimatch": {
"version": "10.1.1",
"resolved": "https://registry.npmjs.org/minimatch/-/minimatch-10.1.1.tgz",
"integrity": "sha512-enIvLvRAFZYXJzkCYG5RKmPfrFArdLv+R+lbQ53BmIMLIry74bjKzX6iHAm8WYamJkhSSEabrWN5D97XnKObjQ==",
"license": "BlueOak-1.0.0",
"dependencies": {
"@isaacs/brace-expansion": "^5.0.0"
},
"engines": {
"node": "20 || >=22"
},
"funding": {
"url": "https://github.com/sponsors/isaacs"
}
}
}
}
{
"name": "minimatch-escape-contract",
"version": "1.0.0",
"private": true,
"type": "module",
"dependencies": {
"minimatch": "10.1.1"
}
}
import { minimatch, escape } from 'minimatch';
export function escapeGlob(pattern, options = {}) {
return escape(pattern, options);
}
export function escapeGlobWindows(pattern, options = {}) {
return escape(pattern, { windowsPathsNoEscape: true, ...options });
}
export function escapeGlobWithBraces(pattern, options = {}) {
return escape(pattern, { magicalBraces: true, ...options });
}
export function createEscapedMatcher(pattern, options = {}) {
const escapedPattern = escape(pattern, options);
return (filename) => minimatch(filename, escapedPattern, options);
}
import { strict as assert } from 'node:assert';
import { minimatch, escape } from 'minimatch';
import {
escapeGlob,
escapeGlobWindows,
escapeGlobWithBraces,
createEscapedMatcher
} from '../src/index.mjs';
// Symbol export verification
assert.equal(typeof minimatch.escape, 'function');
assert.equal(minimatch.escape, escape);
// Windows path escaping: character class enclosure of wildcards without escaping backslashes
const winPathWithWildcard = 'dir\\*.txt';
const winEscaped = escapeGlobWindows(winPathWithWildcard);
assert.equal(winEscaped, 'dir\\[*].txt');
const winPathWithClass = 'data\\item[1].log';
assert.equal(escapeGlobWindows(winPathWithClass), 'data\\item[[]1[]].log');
const winPathWithExtglob = 'path\\sub\\@(alpha|beta)';
assert.equal(escapeGlobWindows(winPathWithExtglob), 'path\\sub\\@[(]alpha|beta[)]');
const winPathWithBraces = 'path\\{a,b}';
assert.equal(escapeGlobWindows(winPathWithBraces), 'path\\{a,b}');
assert.equal(escapeGlobWindows(winPathWithBraces, { magicalBraces: true }), 'path\\[{]a,b[}]');
// POSIX default escaping: backslash prefixing for wildcards, brackets, parentheses, and backslashes
assert.equal(escapeGlob('file[1]*.js'), 'file\\[1\\]\\*.js');
assert.equal(escapeGlob('path\\to\\file'), 'path\\\\to\\\\file');
assert.equal(escapeGlob('alpha?beta*gamma'), 'alpha\\?beta\\*gamma');
// Extglob modifiers: extglob prefixes are kept as literals while parentheses are escaped to deactivate expansion
assert.equal(escapeGlob('+(a|b)'), '+\\(a|b\\)');
assert.equal(escapeGlob('@(a|b)'), '@\\(a|b\\)');
assert.equal(escapeGlob('!(a|b)'), '!\\(a|b\\)');
assert.equal(escapeGlob('?(a|b)'), '\\?\\(a|b\\)');
assert.equal(escapeGlob('*(a|b)'), '\\*\\(a|b\\)');
// Brace expansion escaping: braces remain unescaped unless magicalBraces is explicitly enabled
assert.equal(escapeGlob('{a,b}'), '{a,b}');
assert.equal(escapeGlobWithBraces('{a,b}'), '\\{a,b\\}');
assert.equal(escapeGlobWithBraces('prefix_{0..9}_suffix'), 'prefix_\\{0..9\\}_suffix');
// minimatch.defaults binds preset options to escape
const configuredWin = minimatch.defaults({ windowsPathsNoEscape: true });
assert.equal(configuredWin.escape('logs\\*.*'), 'logs\\[*].[*]');
const configuredMagical = minimatch.defaults({ magicalBraces: true });
assert.equal(configuredMagical.escape('{lib,dist}/*.mjs'), '\\{lib,dist\\}/\\*.mjs');
// Escaped pattern matching behaves as strict literal matcher
const literalTarget = 'archive-[2024]-(v1)*.tar.gz';
const matcher = createEscapedMatcher(literalTarget);
assert.equal(matcher(literalTarget), true);
assert.equal(matcher('archive-2-(v1)extra.tar.gz'), false);
assert.equal(minimatch('archive-2-(v1)extra.tar.gz', literalTarget), true);
console.log('CONTRACT PASS: minimatch.escape verified');