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);
|
$pattern = str_replace('//', '/', $pattern);
|
||||||
$patternParts = explode('/', $pattern);
|
$patternParts = explode('/', $pattern);
|
||||||
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
$patternParts = explode('/', $pattern);
|
$patternParts = explode('/', $pattern);
|
||||||
$shiftCount = sizeof($patternParts);
|
$shiftCount = sizeof($patternParts);
|
||||||
@ -240,7 +241,6 @@ class HTTPRequest extends Object implements ArrayAccess {
|
|||||||
|
|
||||||
$matched = true;
|
$matched = true;
|
||||||
$arguments = array();
|
$arguments = array();
|
||||||
|
|
||||||
foreach($patternParts as $i => $part) {
|
foreach($patternParts as $i => $part) {
|
||||||
$part = trim($part);
|
$part = trim($part);
|
||||||
|
|
||||||
@ -263,6 +263,10 @@ class HTTPRequest extends Object implements ArrayAccess {
|
|||||||
return false;
|
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
|
// Literal parts must always be there
|
||||||
} else if(!isset($this->dirParts[$i]) || $this->dirParts[$i] != $part) {
|
} else if(!isset($this->dirParts[$i]) || $this->dirParts[$i] != $part) {
|
||||||
return false;
|
return false;
|
||||||
|
@ -56,6 +56,16 @@ class RequestHandlingTest extends SapphireTest {
|
|||||||
$response = Director::test("testBadBase/TestForm/fields/MyField");
|
$response = Director::test("testBadBase/TestForm/fields/MyField");
|
||||||
$this->assertNotEquals("MyField requested", $response->getBody());
|
$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
|
// By default, the entire URL will be shifted off. This creates a bit of backward-incompatability, but makes the
|
||||||
// URL rules much more explicit.
|
// URL rules much more explicit.
|
||||||
'testBadBase/$Action/$ID/$OtherID' => "RequestHandlingTest_Controller",
|
'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'];
|
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() {
|
function TestForm() {
|
||||||
return new RequestHandlingTest_Form($this, "TestForm", new FieldSet(
|
return new RequestHandlingTest_Form($this, "TestForm", new FieldSet(
|
||||||
new RequestHandlingTest_FormField("MyField")
|
new RequestHandlingTest_FormField("MyField")
|
||||||
|
Loading…
Reference in New Issue
Block a user