Skip to content

fix: [:print:] class matches printable characters, not control - #309

Open
mahirhir wants to merge 1 commit into
isaacs:mainfrom
mahirhir:fix-posix-print-class
Open

fix: [:print:] class matches printable characters, not control#309
mahirhir wants to merge 1 commit into
isaacs:mainfrom
mahirhir:fix-posix-print-class

Conversation

@mahirhir

@mahirhir mahirhir commented Jun 29, 2026

Copy link
Copy Markdown

The [:print:] POSIX character class is translated to [\p{C}], the set of control characters. Without a negation flag it matches control characters and never matches printable ones, so the result is inverted:

minimatch('a', '[[:print:]]')     // false (should be true)
minimatch(' ', '[[:print:]]')     // false (should be true)
minimatch('\x01', '[[:print:]]')  // true  (should be false)

[:print:] should match every printable character, i.e. everything except control characters, including the space. The sibling [:graph:] class uses the same \p{C} exclusion and is already negated correctly (['\\p{Z}\\p{C}', true, true]); [:print:] is the only class that takes the \p{C} exclusion approach but is missing the negation flag.

The fix adds the flag so [:print:] becomes [^\p{C}]:

-    '[:print:]': ['\\p{C}', true],
+    '[:print:]': ['\\p{C}', true, true],

Added test/posix-class-print.ts. It fails on the current code (the printable assertions return false) and passes with the change. The full suite stays green; no existing tests or snapshots reference [:print:].

The [:print:] POSIX class was translated to `[\p{C}]`, which matches
control characters and never matches printable ones, so a pattern like
`[[:print:]]` failed to match `a` and matched `\x01` instead.

Negate it to `[^\p{C}]`, mirroring the sibling [:graph:] class, so it
matches every character except control characters (space included).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant