mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
BUG Fix HTTP url rewriting
This commit is contained in:
parent
749d28a3c9
commit
a0213aa2bf
@ -104,7 +104,7 @@ class HTTP {
|
||||
* @param string|callable $code Either a string that can evaluate to an expression to rewrite links
|
||||
* (depreciated), or a callable that takes a single parameter and returns the rewritten URL.
|
||||
*
|
||||
* @return The content with all links rewritten as per the logic specified in $code.
|
||||
* @return string The content with all links rewritten as per the logic specified in $code.
|
||||
*/
|
||||
public static function urlRewriter($content, $code) {
|
||||
if(!is_callable($code)) {
|
||||
@ -132,14 +132,15 @@ class HTTP {
|
||||
|
||||
// Callback for regexp replacement
|
||||
$callback = function($matches) use($code) {
|
||||
// Decode HTML attribute
|
||||
$URL = Convert::xml2raw($matches[2]);
|
||||
if(is_callable($code)) {
|
||||
$rewritten = $code($matches[2]);
|
||||
$rewritten = $code($URL);
|
||||
} else {
|
||||
// Expose the $URL variable to be used by the $code expression
|
||||
$URL = $matches[2];
|
||||
$rewritten = eval("return ($code);");
|
||||
}
|
||||
return $matches[1] . $rewritten . $matches[3];
|
||||
return $matches[1] . Convert::raw2xml($rewritten) . $matches[3];
|
||||
};
|
||||
|
||||
// Execute each expression
|
||||
|
@ -278,6 +278,12 @@ class HTTPTest extends FunctionalTest {
|
||||
'<link href=http://www.silverstripe.org/base.css />',
|
||||
HTTP::absoluteURLs('<link href=base.css />')
|
||||
);
|
||||
|
||||
// Test special characters are retained
|
||||
$test->assertEquals(
|
||||
'<a href="http://www.silverstripe.org/Security/changepassword?m=3&t=7214fdfde">password reset link</a>',
|
||||
HTTP::absoluteURLs('<a href="/Security/changepassword?m=3&t=7214fdfde">password reset link</a>')
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user