iwyg / jitimage

Just In Time image manipulation (GD, Imagick, imagemagick) with integration for laravel 4
MIT License
95 stars 8 forks source link

Routes throwing up errors #5

Closed webal closed 11 years ago

webal commented 11 years ago

I've done a basic install from the latest code and set up the provider/facade as per the docs. I have uploaded a file (public/image.jpg and another to public/images/image.jpg) to the public path of the app, and the important parts of the published config file are:

'route'      => 'images',
'base'       => public_path(), 
'recipes' => [
    'thumbs' => '2/200/200/5, filter:gs'
],

the recipes line is the only one I have changed.

When I look at my routes (php artisan route) I can see the thumbnail route defined as:

GET /images/thumbs/{source}        |         | Thapp\JitImage\Controller\JitController@getResource

When I visit domain.dev/images/thumbs/image.jpg or domain.dev/images/thumbs/images/image.jpg I get th following error:

preg_match(): Compilation failed: nothing to repeat at offset 79

The stacktrace shows:

 protected function matchCollection($pathinfo, RouteCollection $routes)
{
foreach ($routes as $name => $route) {
$compiledRoute = $route->compile();
if ('' !== $compiledRoute->getStaticPrefix() && 0 !== strpos($pathinfo, $compiledRoute->getStaticPrefix())) {
continue;
}
if (!preg_match($compiledRoute->getRegex(), $pathinfo, $matches)) {                         <- error on this line
continue;
}

It may be that I'm doing something wrong, but I can't see how. I'm running it on WAMP as development (not production) environment locally if that makes any difference

iwyg commented 11 years ago

Thanks, I'll have a look at this.

iwyg commented 11 years ago

Hm, that's odd. Seems like there's a problme if the dynamic part of the uri is named {source}, although I'm getting a different error than your's (not found exception). Changing the dynamic part to something else however works fine. I'll have to investigate this a little more.

There was a wrong where clause in the static routes' setup. Although this may apply to your issue, I'm not 100% sure as I'm not able to reproduce your error. Please grab the latest code from the master branch and have try. Cheers.

webal commented 11 years ago

Thanks, If there's any more information you need from me please let me know...

iwyg commented 11 years ago

Just updated the comment above. Can you try the latest commit on master?

iwyg commented 11 years ago

Does this although occur when you use dynamic processing instead? Could be a windows related bug then.

webal commented 11 years ago

Hi, that last commit seems to have fixed it :D thanks so much! It looks like a great package btw

I'm not planning to use the dynamic processing, but I did just try the following URL:

domain.dev/images/2/200/200/5/images/image.jpg

and I got a similar error (preg_match(): Compilation failed: nothing to repeat at offset 185 ):

protected function matchCollection($pathinfo, RouteCollection $routes)
{
foreach ($routes as $name => $route) {
$compiledRoute = $route->compile();
if ('' !== $compiledRoute->getStaticPrefix() && 0 !== strpos($pathinfo, $compiledRoute->getStaticPrefix())) {
continue;
}
if (!preg_match($compiledRoute->getRegex(), $pathinfo, $matches)) {  // <-- error on this line
continue;
}

I'm happy to test a fix if you think there may be a bug there.

iwyg commented 11 years ago

Thanks. What php version is running on your xampp?

webal commented 11 years ago

It's WAMP not XAMPP, but the PHP is 5.4.3

iwyg commented 11 years ago

hm, that's odd. Tested on windows7 with php 5.4.16 and it's all working well. I've spotted another but that wouldn't allow images to be directly in the public folder, but that's not related with your issue :(

webal commented 11 years ago

strange, I'm not planning to use dynamic processing though so it's working great for me now.

iwyg commented 11 years ago

hm, I'll try to setup a 5.4.3 version on my windows vm. Are you running the 32bit or the 64bit WAMP version?

iwyg commented 11 years ago

Ok, can confirm this. It's a bug that occurs in php 5.4.3.

webal commented 11 years ago

Guess it's time for me to update :/

It was the 64bit version btw

iwyg commented 11 years ago

it's strange. The error is caused from a positive lookahead in my regexp here (the last part).

iwyg commented 11 years ago

ok, guess I fixed it. Can you confirm?

webal commented 11 years ago

That's working now - great job :)