This commit is contained in:
Guido Schmechel 2023-11-12 05:30:38 +13:00 committed by GitHub
commit 52d04b93db
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 2 additions and 38 deletions

View File

@ -228,13 +228,6 @@ class ContentNegotiator
$content = $response->getBody();
$hasXMLHeader = (substr($content ?? '', 0, 5) == '<' . '?xml');
// Fix base tag
$content = preg_replace(
'/<base href="([^"]*)" \/>/',
'<base href="$1"><!--[if lte IE 6]></base><![endif]-->',
$content ?? ''
);
$content = preg_replace("#<\\?xml[^>]+\\?>\n?#", '', $content ?? '');
$content = str_replace(
['/>', 'xml:lang', 'application/xhtml+xml'],

View File

@ -854,13 +854,6 @@ PHP;
*/
public static function get_base_tag($contentGeneratedSoFar)
{
$base = Director::absoluteBaseURL();
// Is the document XHTML?
if (preg_match('/<!DOCTYPE[^>]+xhtml/i', $contentGeneratedSoFar ?? '')) {
return "<base href=\"$base\" />";
} else {
return "<base href=\"$base\"><!--[if lte IE 6]></base><![endif]-->";
}
return '<base href="' . Director::absoluteBaseURL() . '" />';
}
}

View File

@ -962,35 +962,13 @@ after'
</html>';
$this->assertMatchesRegularExpression('/<head><base href=".*" \/><\/head>/', $this->render($tmpl1));
// HTML4 and 5 will only have it for IE
$tmpl2 = '<!DOCTYPE html>
<html>
<head><% base_tag %></head>
<body><p>test</p><body>
</html>';
$this->assertMatchesRegularExpression(
'/<head><base href=".*"><!--\[if lte IE 6\]><\/base><!\[endif\]--><\/head>/',
$this->render($tmpl2)
);
$tmpl3 = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head><% base_tag %></head>
<body><p>test</p><body>
</html>';
$this->assertMatchesRegularExpression(
'/<head><base href=".*"><!--\[if lte IE 6\]><\/base><!\[endif\]--><\/head>/',
$this->render($tmpl3)
);
// Check that the content negotiator converts to the equally legal formats
$negotiator = new ContentNegotiator();
$response = new HTTPResponse($this->render($tmpl1));
$negotiator->html($response);
$this->assertMatchesRegularExpression(
'/<head><base href=".*"><!--\[if lte IE 6\]><\/base><!\[endif\]--><\/head>/',
'/<head><base href=".*" \/><\/head>/',
$response->getBody()
);