Skip to content
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

composer archive crashes on bad line in .gitignore file #7440

Open
mborne opened this issue Jul 3, 2018 · 2 comments
Open

composer archive crashes on bad line in .gitignore file #7440

mborne opened this issue Jul 3, 2018 · 2 comments
Milestone

Comments

@mborne
Copy link

@mborne mborne commented Jul 3, 2018

Hello,

I have a full satis build generation that is interrupted with a preg_match(): Compilation failed: missing ) at offset 24 when composer archive is invoked on a specific project tag.

It seams that composer archive crashes in archive generation when .gitignore contains strange lines.

For example, /${ctx will lead to the following invocation in https://github.com/composer/composer/blob/1.6.5/src/Composer/Package/Archiver/BaseExcludeFilter.php#L62 :

preg_match('{^/(?=[^\.])\$(ctx(?=$|/)}','/CHANGELOG.md')
// => preg_match(): Compilation failed: missing ) at offset 24

Would it be possible to validate $pattern and ignore invalid ones?

PS :

@Seldaek
Copy link
Member

@Seldaek Seldaek commented Jul 17, 2018

Not sure if this is a bug in Composer or Finder\Glob::toRegex or just a borked .gitignore rule that should have no place being there in the first place, but if someone can fix it I guess why not. Doesn't seem very high prio though.

@Seldaek Seldaek added this to the Bugs milestone Jul 17, 2018
@jrfnl
Copy link
Contributor

@jrfnl jrfnl commented Sep 15, 2018

I've had a look at this issue and my conclusion would be that it is a borked .gitignore rule that should have no place being there in the first place.

The test case graciously provided by @mborne shows that the issue is still reproducible on the current master.

The only adjustment to Finder\Glob::toRegex which could be made IMO, would be a check that any opening brace also has a close brace and if not, escape the brace instead of changing it.
Aside from the fact that that check would be quite complicated as it would need to account for already escaped braces, I'm not sure that the method should account for invalid glob patterns.

As for Composer, a simple solution could be to prefix the filter preg_match() with the error silencing operator.
preg_match() would return false anyway, so the value of $exclude would not be changed and the tar file would be created as expected.

if (preg_match($pattern, $path)) {

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
4 participants
You can’t perform that action at this time.