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

Revert "[stable10] generated resource routes should allow slashes" #31932

Merged
merged 1 commit into from
Jun 28, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/private/AppFramework/Routing/RouteConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ private function processResources($routes)

$this->router->create($routeName, $url)->method($verb)->action(
new RouteActionHandler($this->container, $controllerName, $actionName)
)->requirements(['id' => '.+']); // allow / in {id} parameter
);
}
}
}
Expand Down
76 changes: 2 additions & 74 deletions tests/lib/Route/RouterTest.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?php
/**
* @author Jörn Friedrich Dreyer <[email protected]>
* @author Thomas Müller <[email protected]>
*
* @copyright Copyright (c) 2018, ownCloud GmbH
Expand All @@ -25,41 +24,17 @@

use OC\Route\Router;
use OCP\ILogger;
use Symfony\Component\Routing\Exception\ResourceNotFoundException;

class LoadableRouter extends Router {
/**
* @param bool $loaded
*/
public function setLoaded($loaded) {
$this->loaded = $loaded;
}
}

class RouterTest extends \Test\TestCase {

/** @var ILogger */
private $l;

/**
* RouterTest constructor.
*
* @param string $name
* @param array $data
* @param string $dataName
*/
public function __construct($name = null, array $data = [], $dataName = '') {
parent::__construct($name, $data, $dataName);
$this->l = $this->createMock(ILogger::class);
}

/**
* @dataProvider providesWebRoot
* @param $expectedBase
* @param $webRoot
*/
public function testWebRootSetup($expectedBase, $webRoot) {
$router = new Router($this->l, $webRoot);
$l = $this->createMock(ILogger::class);
$router = new Router($l, $webRoot);

$this->assertEquals($expectedBase, $router->getGenerator()->getContext()->getBaseUrl());
}
Expand All @@ -72,51 +47,4 @@ public function providesWebRoot() {
['/oc/index.php', '/oc/'],
];
}

/**
* @dataProvider urlParamSlashProvider
*/
public function testMatchURLParamContainingSlash($routeUrl, $slashesAllowed, $matchUrl, $expectedCalled) {
$router = new LoadableRouter($this->l, '');

$called = false;

$router->useCollection('root');
$route = $router->create('test', $routeUrl)
->action(function () use (&$called) {
$called = true;
});
if ($slashesAllowed) {
$route->requirements(['id' => '.+']);
}

// don't load any apps
$router->setLoaded(true);

try {
$router->match($matchUrl);
} catch (ResourceNotFoundException $e) {
$called = false;
}

self::assertEquals($expectedCalled, $called);
}

public function urlParamSlashProvider() {
return [
// slashed disallowed
['/resource/{id}', false, '/resource/id%2Fwith%2Fslashes', false],
['/resource/{id}/sub', false, '/resource/id%2Fwith%2Fslashes/sub', false],
['/resource/{id}/sub', false, '/resource/id%2Fwith%2Fslashes/subx', false],
['/resource/{id}', false, '/resource/id/with/slashes', false],
['/resource/{id}/sub', false, '/resource/id/with/slashes/sub', false],

// slashed allowed
['/resource/{id}', true, '/resource/id%2Fwith%2Fslashes', true],
['/resource/{id}/sub', true, '/resource/id%2Fwith%2Fslashes/sub', true],
['/resource/{id}/sub', true, '/resource/id%2Fwith%2Fslashes/subx', false],
['/resource/{id}', true, '/resource/id/with/slashes', true],
['/resource/{id}/sub', true, '/resource/id/with/slashes/sub', true],
];
}
}