IgnoreFile: trailing space after an escaped backslash isn't trimmed

Open Beginner friendly
#55,517 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
76/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
php
Domain
backend

Research direction

Start in projects/packages/ignorefile/src/IgnoreFile.php at the trailing-space trim regex identified in the issue, then compare its behavior with Git’s backslash handling test linked in the report. Reproduce the example with the package and verify the pattern matches the path after the fix; confirm the existing ignorefile tests still pass.

Written by the indexing model from the issue text.

Description

In the ignorefile package (automattic/ignorefile 4.0.0), a pattern that ends in an escaped backslash and then a space keeps the space. Git trims it, since the backslash pair is the escaped part and the space isn't.

<?php
require 'vendor/autoload.php';

$ignore = new \Automattic\IgnoreFile();
$ignore->add( 'trailing 3 ' . str_repeat( '\\', 4 ) . ' ' );
var_dump( $ignore->ignores( 'trailing 3 ' . str_repeat( '\\', 2 ) ) );

This prints bool(false). With the same rule in a .gitignore, git check-ignore lists that path. It's the third path in Git's backslash handling test in v2.56.1.

The trim regex (?<!\\\\) +$ only looks at the one character before the spaces, so any backslash there blocks the trim, even when it's the second half of a \\ pair. The regex is the same on trunk.

Dominant language
PHP
Stars
1.9k
Forks
910
Avg merge
1d 18h
Merged PRs (30d)
777

Getting set up

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.

More from Automattic/jetpack

All issues in Automattic/jetpack

Similar issues

More PHP issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.