Skip to content

Commit

Permalink
Merge pull request #15532 from seyfer/extract-twig-for-url
Browse files Browse the repository at this point in the history
extract TWIG for url.php and fix formatting #14801
  • Loading branch information
MauricioFauth committed Oct 30, 2019
2 parents cccf849 + c0a93fa commit 1360cca
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 26 deletions.
14 changes: 9 additions & 5 deletions templates/javascript/display.twig
@@ -1,7 +1,11 @@
<script type="text/javascript">
if (typeof configInlineParams === "undefined" || !Array.isArray(configInlineParams)) configInlineParams = [];
configInlineParams.push(function() {
{{ js_array|join(';\n')|raw }};
});
if (typeof configScriptLoaded !== "undefined" && configInlineParams) loadInlineConfig();
if (typeof configInlineParams === 'undefined' || !Array.isArray(configInlineParams)) {
configInlineParams = [];
}
configInlineParams.push(function () {
{{ js_array|join(';\n')|raw }};
});
if (typeof configScriptLoaded !== 'undefined' && configInlineParams) {
loadInlineConfig();
}
</script>
5 changes: 5 additions & 0 deletions templates/javascript/redirect.twig
@@ -0,0 +1,5 @@
<script type='text/javascript'>
window.onload = function () {
window.location = '{{ url }}';
};
</script>
35 changes: 19 additions & 16 deletions test/classes/Config/FormDisplayTemplateTest.php
Expand Up @@ -548,8 +548,8 @@ public function testAddJsValidate()
$this->assertEquals(
[
'registerFieldValidator(\'testID\', \'\\\';\', true, '
. '[\'\\\\r\\\\n\\\\\\\''
. '<scrIpt></\\\' + \\\'script>\'])',
. '[\'\\\\r\\\\n\\\\\\\''
. '<scrIpt></\\\' + \\\'script>\'])',
'registerFieldValidator(\'testID\', \'\', true)',
],
$js
Expand All @@ -570,19 +570,22 @@ public function testDisplayJavascript()

$result = $this->formDisplayTemplate->displayJavascript(['var i = 1', 'i++']);

$this->assertEquals(
'<script type="text/javascript">' . "\n"
. 'if (typeof configInlineParams === "undefined"'
. ' || !Array.isArray(configInlineParams)) '
. 'configInlineParams = [];' . "\n"
. 'configInlineParams.push(function() {' . "\n"
. 'var i = 1;' . "\n"
. 'i++;' . "\n"
. '});' . "\n"
. 'if (typeof configScriptLoaded !== "undefined"'
. ' && configInlineParams) loadInlineConfig();'
. "\n" . '</script>' . "\n",
$result
);
$jsTemplate = <<<HTML
<script type="text/javascript">
if (typeof configInlineParams === 'undefined' || !Array.isArray(configInlineParams)) {
configInlineParams = [];
}
configInlineParams.push(function () {
var i = 1;
i++;
});
if (typeof configScriptLoaded !== 'undefined' && configInlineParams) {
loadInlineConfig();
}
</script>
HTML;

$this->assertEquals($jsTemplate, $result);
}
}
9 changes: 4 additions & 5 deletions url.php
Expand Up @@ -41,11 +41,10 @@
// then web browser sometimes does not change the HTTP_REFERER
// field and so with old URL as Referer, token also goes to
// external site.
echo "<script type='text/javascript'>
window.onload=function(){
window.location='" , Sanitize::escapeJsString($_GET['url']) , "';
}
</script>";
$template = $containerBuilder->get('template');
echo $template->render('javascript/redirect', [
'url' => Sanitize::escapeJsString($_GET['url']),
]);
// Display redirecting msg on screen.
// Do not display the value of $_GET['url'] to avoid showing injected content
echo __('Taking you to the target site.');
Expand Down

0 comments on commit 1360cca

Please sign in to comment.