mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
BUGFIX Allowing HTTPRequest::match() to match rules with extensions (e.g. /sitemap.xml used for GoogleSitemap)
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@62471 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
parent
3c02398e33
commit
65e9165905
@ -233,6 +233,7 @@ class HTTPRequest extends Object implements ArrayAccess {
|
||||
$pattern = str_replace('//', '/', $pattern);
|
||||
$patternParts = explode('/', $pattern);
|
||||
|
||||
|
||||
} else {
|
||||
$patternParts = explode('/', $pattern);
|
||||
$shiftCount = sizeof($patternParts);
|
||||
@ -240,10 +241,9 @@ class HTTPRequest extends Object implements ArrayAccess {
|
||||
|
||||
$matched = true;
|
||||
$arguments = array();
|
||||
|
||||
foreach($patternParts as $i => $part) {
|
||||
$part = trim($part);
|
||||
|
||||
|
||||
// Match a variable
|
||||
if(isset($part[0]) && $part[0] == '$') {
|
||||
// A variable ending in ! is required
|
||||
@ -262,7 +262,11 @@ class HTTPRequest extends Object implements ArrayAccess {
|
||||
if($part == '$Controller' && !class_exists($arguments['Controller'])) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
// Literal parts with extension
|
||||
} else if(isset($this->dirParts[$i]) && $this->dirParts[$i] . '.' . $this->extension == $part) {
|
||||
continue;
|
||||
|
||||
// Literal parts must always be there
|
||||
} else if(!isset($this->dirParts[$i]) || $this->dirParts[$i] != $part) {
|
||||
return false;
|
||||
|
@ -56,6 +56,16 @@ class RequestHandlingTest extends SapphireTest {
|
||||
$response = Director::test("testBadBase/TestForm/fields/MyField");
|
||||
$this->assertNotEquals("MyField requested", $response->getBody());
|
||||
}
|
||||
|
||||
function testBaseWithExtension() {
|
||||
/* Rules with an extension always default to the index() action */
|
||||
$response = Director::test("testBaseWithExtension/virtualfile.xml");
|
||||
$this->assertEquals("This is the controller", $response->getBody());
|
||||
|
||||
/* Without the extension, the methodname should be matched */
|
||||
$response = Director::test("testBaseWithExtension/virtualfile");
|
||||
$this->assertEquals("This is the virtualfile method", $response->getBody());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -73,6 +83,12 @@ Director::addRules(50, array(
|
||||
// By default, the entire URL will be shifted off. This creates a bit of backward-incompatability, but makes the
|
||||
// URL rules much more explicit.
|
||||
'testBadBase/$Action/$ID/$OtherID' => "RequestHandlingTest_Controller",
|
||||
|
||||
// Rules with an extension always default to the index() action
|
||||
'testBaseWithExtension/virtualfile.xml' => "RequestHandlingTest_Controller",
|
||||
|
||||
// Without the extension, the methodname should be matched
|
||||
'testBaseWithExtension//$Action/$ID/$OtherID' => "RequestHandlingTest_Controller",
|
||||
));
|
||||
|
||||
/**
|
||||
@ -96,6 +112,10 @@ class RequestHandlingTest_Controller extends Controller {
|
||||
return "\$this->urlParams can be used, for backward compatibility: " . $this->urlParams['ID'] . ', ' . $this->urlParams['OtherID'];
|
||||
}
|
||||
|
||||
function virtualfile($request) {
|
||||
return "This is the virtualfile method";
|
||||
}
|
||||
|
||||
function TestForm() {
|
||||
return new RequestHandlingTest_Form($this, "TestForm", new FieldSet(
|
||||
new RequestHandlingTest_FormField("MyField")
|
||||
|
Loading…
Reference in New Issue
Block a user