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

Resource route length > 32 characters throws preg_match() errror. #1001

Closed
JordanDalton opened this issue Apr 18, 2013 · 15 comments
Closed

Resource route length > 32 characters throws preg_match() errror. #1001

JordanDalton opened this issue Apr 18, 2013 · 15 comments

Comments

@JordanDalton
Copy link

When I try to delete a specified resource using a uri that is greater than 32 characters the following error is encountered:

Warning: preg_match(): Compilation failed: subpattern name is too long (maximum 32 characters) at offset 80 in C:\apps\grahamsqbapi\bootstrap\compiled.php line 15188

My defined route:

// "salesorderlinedetaildepartmentemployees" is used to match the table name (gotta love quickbooks..)
Route::resource('salesorderlinedetaildepartmentemployees', 'Api_SalesOrderLineDetailDepartmentEmployeeController', array('only' => array('index', 'destroy')));

If I shorten "salesorderlinedetaildepartmentemployees" to "salesorderlinedetaildepartmentem" everything executes just fine.

Requested solution: Extend how long the resource route uri can be.

@taylorotwell
Copy link
Member

That's a Symfony thing. You can file an issue on their repository for their routing component asking for this.

@thinksaydo
Copy link
Contributor

I've opened an issue in the Symfony repository: symfony/symfony#8933

We're also looking into ways to work around or correct this problem.

@stof
Copy link

stof commented Sep 5, 2013

@taylorotwell Is it rally a Symfony issue ? From a quick look, Illuminate\Routing is not based on the Symfony Routing component

@taylorotwell
Copy link
Member

Master branch isn't... 4.0 branch is. @stof

@thinksaydo
Copy link
Contributor

Looks like this is being pushed back up as a Laravel specific issue on how it uses Symfony's routing. We'll look into this further to see what can be done on L4's side and offer a pull request if we find an elegant solution. Otherwise, for now, we're just making sure slugs are never over 32 characters.

@vespakoen
Copy link
Contributor

Having the same problem, stumbled upon the Symfony issue @thinksaydo created, now back over here.

@taylorotwell can you re-open this please?

@fhferreira
Copy link

+1 on L4.2

@GrahamCampbell
Copy link
Member

4.2 isn't supported

@fhferreira
Copy link

tks, i will try another solution.

@dexmans
Copy link

dexmans commented Aug 26, 2015

This issue still exists in Laravel 5.1.10.

When using long resource names, the ResourceRegistrar::getResourceWildcard() method can return strings which exceeds 32 characters, resulting in the same error as above.
The only workarounds are to adjust the resource name (making it less descriptive) or manually adding routes and use a custom placeholder like $x->get(my-really-really-really-really-long-route-name-here/{customShortPlaceholder}', \App\Http\Controllers\XxController@xx');`

It would be nice to be able to set the preferred placeholder names in the resource options and/or making the getResourceWildcard() method handle these cases differently.

Just putting this here instead of creating a new issue directly to check if it's something that will be fixed as it has been in since L4.

@MarioBDourado
Copy link

Still exists in Laravel 5.1.24 (LTS).

@mysteryos
Copy link

Bumped into this issue as well today (Laravel 5.1.26). Ball is in your court laravel.

@GrahamCampbell
Copy link
Member

If were were to "fix" this, we still wouldn't allow more than 32 characters. We'd just change the warning into an exception.

@mcordingley
Copy link
Contributor

mcordingley commented Apr 20, 2016

Per http://pcre.org/current/doc/html/pcre2pattern.html#SEC16 PCRE sub-patterns cannot be longer than 32 characters, so there's unfortunately nothing that Symfony can do about this. Their comment on this issue: symfony/symfony#8933 (comment) states "[Laravel] should allow you to decouple the url prefix and the placeholder name." which could be a useful work-around.

Probably the real issue here is that running into the 32 character limit is surprise and that the exception thrown is from far enough down the call graph and so it looks like a bug in Laravel, even though it really isn't. Either way you slice it, the solution is to use a shorter sub-pattern name, either through shortening the argument to Route::resource or through some alias mechanism as the Symfony folks suggested. Proactively throwing a more specific exception, as @GrahamCampbell noted, would at least offer a kind of documentation that patterns above a certain length are explicitly not supported. That should stop people from coming into this thread to resurrect it or opening duplicates.

@lagbox
Copy link
Contributor

lagbox commented Mar 16, 2017

If this is just an issue with the route parameter, placeholder, we can now change that via the options array to Route::resource to get around that limitation.

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

No branches or pull requests