Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[Finder] Escape location for regex searches #11970

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed

Conversation

ymc-dabe
Copy link
Contributor

Q A
Bug fix? yes
New feature? no
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets -
License MIT
Doc PR -

If the location to start searching in contains a regex special char
like + or ? and the path restriction is a regular expresion with a start
limitation. No results will be found wtih at least GnuFindAdapter - e.g.:

use Symfony\Component\Finder\Finder;
use Symfony\Component\Finder\Adapter;

mkdir('/tmp/reg+ex/dir/subdir', 0777, true);

$finder = Finder::create()
    ->removeAdapters()
    ->addAdapter(new Adapter\GnuFindAdapter());
$finder->in('/tmp/reg+ex')->path('/^dir/');

print count($finder)."\n";

Expected result: 2
Actual result is: 0

This pull request consists of:

  • a new test checking for this bug (0e81086)
  • the actual fix (6595b6b)
  • changes to comply with the coding standard (7f199c5)

How to reproduce

Fastest way

  1. Move or copy your local symfony clone into a location containing special regex chars:
    • mv symfony symfony+regex
  2. Run tests in there
    • cd symfony+regex && phpunit

Result: Some tests in the finder component will fail.

Alternative: A new clone

  1. Clone symfony in a directory containing at least one regex special char
    • git clone https://github.com/symfony/symfony.git /tmp/symfony+regexchar
  2. As usual get composer, install dependencies and get phpunit
  3. Run tests in there
    • cd /tmp/symfony+regexchar && phpunit

Result: Some tests in the finder component will fail.

Alternative: Apply the new test

  1. Apply commit a29d120 to your symfony clone
  2. Run tests

Result: The new test will fail.

If the location to start searching in contains a regex special char
like + or ? and the path restriction is a regular expression with a start
limitation. No results will be found with at least GnuFindAdapter - e.g.:
```
use Symfony\Component\Finder\Finder;
use Symfony\Component\Finder\Adapter;

mkdir('/tmp/reg+ex/dir/subdir', 0777, true);

$finder = Finder::create()
    ->removeAdapters()
    ->addAdapter(new Adapter\GnuFindAdapter());
$finder->in('/tmp/reg+ex')->path('/^dir/');

print count($finder)."\n";
```

Expected result: 2
Actual result is: 0
…th '^'

Previously to this commit at least GnuFindAdapter find no result in locations
containing regex special chars (e.g. + or ?) and the path restriction is a
regular expression with a start limitation (the regex starts with ^).
@ymc-dabe ymc-dabe force-pushed the finder-escape-location-for-regex-searches branch from 681aa7b to 6595b6b Compare September 20, 2014 15:12
... as suggested by fabbot.io
@ymc-dabe ymc-dabe changed the title [WIP] [Finder] Escape location for regex searches [Finder] Escape location for regex searches Sep 20, 2014
@jakzal jakzal added the Finder label Sep 21, 2014
@fabpot
Copy link
Member

fabpot commented Sep 22, 2014

Thank you @ymc-dabe.

fabpot added a commit that referenced this pull request Sep 22, 2014
This PR was squashed before being merged into the 2.3 branch (closes #11970).

Discussion
----------

[Finder] Escape location for regex searches

| Q             | A
| ------------- | ---
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | -
| License       | MIT
| Doc PR        | -

If the location to start searching in contains a regex special char
like + or ? and the path restriction is a regular expresion with a start
limitation. No results will be found wtih at least GnuFindAdapter - e.g.:
```
use Symfony\Component\Finder\Finder;
use Symfony\Component\Finder\Adapter;

mkdir('/tmp/reg+ex/dir/subdir', 0777, true);

$finder = Finder::create()
    ->removeAdapters()
    ->addAdapter(new Adapter\GnuFindAdapter());
$finder->in('/tmp/reg+ex')->path('/^dir/');

print count($finder)."\n";
```

Expected result: 2
Actual result is: 0

This pull request consists of:
* a new test checking for this bug (0e81086)
* the actual fix (6595b6b)
* changes to comply with the coding standard (7f199c5)

## How to reproduce
### Fastest way
1. Move or copy your local symfony clone into a location containing special regex chars:
  * `mv symfony symfony+regex`
2. Run tests in there
  * `cd symfony+regex && phpunit`

> Result: Some tests in the finder component will fail.

### Alternative: A new clone
1. Clone symfony in a directory containing at least one regex special char
  * `git clone https://github.com/symfony/symfony.git /tmp/symfony+regexchar`
2. As usual get composer, install dependencies and get phpunit
  * You might simply want to follow [this guide](http://symfony.com/doc/current/contributing/code/tests.html)
3. Run tests in there
   * `cd /tmp/symfony+regexchar && phpunit`

> Result: Some tests in the finder component will fail.

### Alternative: Apply the new test
1. Apply commit a29d120 to your symfony clone
2. Run tests

> Result: The new test will fail.

Commits
-------

b63926b [Finder] Escape location for regex searches
@fabpot fabpot closed this Sep 22, 2014
@phazei
Copy link

phazei commented Sep 23, 2014

The tests directory _r+e.g?e_x[c]a(r)s* contains invalid characters in windows so breaks composer install or update because it can't be created. Please revert ASAP and remove that directory name.

@adamthebig
Copy link

Same issue for me. All windows dev machines are now borked.

@phazei
Copy link

phazei commented Sep 23, 2014

Please revert this ASAP, the pull requests removing the invalid characters aren't passing, but this shouldn't have been commited in the first place.

@ymc-dabe
Copy link
Contributor Author

Sorry for breaking this for you. It totally forgot about possible limitations in other filesystems/OS here. And thanks @phazei for proposing a fix!

ymc-dabe added a commit to ymc-dabe/symfony that referenced this pull request Sep 23, 2014
Closes: symfony#11984

Commit b63926b from PR symfony#11970
introduces a directory containing invalid chars for directory
names under windows.
fabpot added a commit that referenced this pull request Sep 23, 2014
…lder name in test to prevent windows file system issues. (Adam)

This PR was merged into the 2.3 branch.

Discussion
----------

[Finder][Urgent] Remove asterisk and question mark from folder name in test to prevent windows file system issues.

Bugfix: Yes
Fixed tickets: #11984 , #11985
Related tickets: #11970

Commit #11970 prevented Symphony from being checked out via windows due to invalid characters in a folder name within the tests.

The issue was reported in #11984  and was attempted to be fixed in #11985 but wasn't due to still including the question mark.

Please accept this ASAP as it entirely breaks any composer that relies on it.

Commits
-------

5fbb278 Avoid question mark and asterisk in folder names to prevent windows filesystem issues.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants