Skip to content

Commit

Permalink
Merge pull request #31932 from owncloud/revert-31927-stable10-fix-sla…
Browse files Browse the repository at this point in the history
…ses-in-urlparams

Revert "[stable10] generated resource routes should allow slashes"
  • Loading branch information
Vincent Petry authored Jun 28, 2018
2 parents 6bb3fde + 19d910a commit cdf9804
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 75 deletions.
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],
];
}
}

0 comments on commit cdf9804

Please sign in to comment.