Trailing Forward Slash in getPathInfo()

In porting some Yii1 code to Yii2 things are going pretty well, but I ran into an issue with a simple URL Rule Class something like this -


class ReviewsUrlRule extends Object implements UrlRuleInterface

{

...


	public function parseRequest($manager, $request)

	{

		//

		// This will match things like

		//  /reviews

		//  /reviews/ford

		//  /reviews/mustang

		//  /reviews/ford/mustang/1235

		// etc...

		//

		// Note the Make and Model has only a 1 or 2 word scan

		// Special chars are handled as part of the character set (think Citroen, Up!, etc) 

		//

		// Might be a better way to do this but that is left as an exercise for the reader...


    	$pathInfo = $request->getPathInfo();


var_dump($pathInfo);

exit(1);

 	

	}


}  

When I take a look at $pathInfo I see a trailing ‘/’. In the docs I see this comment -

I can easily strip the trailing slash in my handler, but want to make sure that either it’s a problem with the yii\web\Request::getPathInfo() or I’m not overlooking something that I should care about. The trailing slash breaks the current (ugly) regex for my url structure.

Sandy

Looks like only the starting slash is removed - https://github.com/yiisoft/yii2/blob/master/framework/web/Request.php#L726

Yep, that’s what it looks like. Not sure if intended to be that way and a bug in the docs.

Thanks for the help, I’ll file a bug and see what gets said. In the meantime I’ll just rtrim() the slash.

So for those that are moving code over from Yii1 to Yii2 and using the getPathInfo() it may contain the trailing slash which is slightly different then expected.

Thanks

Sandy