No route for HTTP request by capitalized first letter

Notice: This thread is very old.
tomcat4x
Member | 22
+
0
-

Hi,

why is there no route when i capitalize the first letter in the presenter part of the url?

http://localhost/…www/homepage is working but http://localhost/…www/Homepage throws a Nette\Application\BadRequestException #404

the only route is:

$router[] = new Route(‘<presenter>/<action>[/<id>]’, ‘Homepage:default’);

So i expected that both calls would redirect me to the homepage presenter. Why not?

Tested with the default sandbox of nette 2.3.7

Pavel Kravčík
Member | 1196
+
0
-

Hey,

David wrote about this here (https://phpfashion.com/…o-url-stejne). You can try use translator, article is czech.

Short version with example:

https://en.wikipedia.org/wiki/Acid
https://en.wikipedia.org/wiki/ACID

These two URLs arent same! So homepage & Homepage arent same as well. I guess Nette expect small first lette for presenter, otherwise throw exception. You can define custom route like this:

$router[] = new Route(‘Homepage/<action>[/<id>]’, ‘Homepage:default’);
tomcat4x
Member | 22
+
0
-

That for an apache these two urls arent the same is clear.

but in nette i thought that <presenter> in routing covers all requests like

http://localhost/homepage, http://localhost/homepage1, http://localhost/homepage2

regardless of capitalized letters.

But as you say, nette seems to expect all letters uncapitalized. Also hOmepage throws an error.

Last edited by tomcat4x (2015-10-20 16:02)

Pavel Kravčík
Member | 1196
+
0
-

You can always implement your own solution. Maybe this help https://doc.nette.org/…tion/routing#….

Also I found this https://doc.nette.org/…tion/routing#…, so regular should be insensitive (https://api.nette.org/…ute.php.html#…).

But here David wrote about case-sensitive presenters (https://phpfashion.com/…sku-citlivka), then flag lose purpose and mb we need flag CASE_INSENSITIVE (terrible name:)).

@DavidGrudl

tomcat4x
Member | 22
+
0
-

But here David wrote about case-sensitive presenters (https://phpfashion.com/…sku-citlivka), then flag lose purpose and mb we need flag CASE_INSENSITIVE (terrible name:)).

Sorry but i cant speak czech.

I had a look at the source code of router.php and it seems that the flag CASE_SENSITIVE has no more effect. It is depreceated. A flag CASE_INSENSITIVE it not present. So someone should revise the documentation.

in the style array, which is responsible for parsing the pattern <presenter> is following code:

	'presenter' => array(
			self::PATTERN => '[a-z][a-z0-9.-]*',
			self::FILTER_IN => array(__CLASS__, 'path2presenter'),
			self::FILTER_OUT => array(__CLASS__, 'presenter2path'),

So capitalized chars wont be matched. The only way is to modify the router.php to somting like that:

	'presenter' => array(
			self::PATTERN => '[A-Za-z][A-Za-z0-9.-]*',
			self::FILTER_IN => array(__CLASS__, 'path2presenter'),
			self::FILTER_OUT => array(__CLASS__, 'presenter2path'),

But because of updates it makes no sense to change a core file of nette. So i have to live with lowercase letters in the url. I was just wondered that i got a no route error. I expected a no presenter error if nette makes a difference between upper and lower case.

Pavel Kravčík
Member | 1196
+
0
-

Yeah, I know. But sometimes you can translate article in browser. :)

You can define your own FILTER_IN/OUT at app/router/RouterFactory – something really simple like strtolower- so hOmepAge → will be homepage. And then you get rid off warnings about Case sensitive URL. But best solution IMHO is using lowercase letters.

tomcat4x
Member | 22
+
0
-

Pavel Kravčík wrote:

Yeah, I know. But sometimes you can translate article in browser. :)

You can define your own FILTER_IN/OUT at app/router/RouterFactory – something really simple like strtolower- so hOmepAge → will be homepage. And then you get rid off warnings about Case sensitive URL. But best solution IMHO is using lowercase letters.

FILTER IN/OUT does not work in this case, because the exception is thrown before ther first filter is executed. But i saw in the source code that you can overwrite the pattern in the route definition

			$router[] = new Route('<presenter=Homepage>/<action=default>', array(
			'presenter' => array(
		Route::PATTERN => '[A-Za-z0-9.-]*',
		Route::FILTER_IN => function($presenter) {
		return ucfirst(strtolower($presenter));
		},
	),
		));

now all presenter calls like hompage, Homepage, HOMEpage … will be processed by the HomepagePresenter.

Last edited by tomcat4x (2015-10-21 18:43)