Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EscapeJs not works properly #164

Closed
MartkCz opened this issue Aug 2, 2017 · 3 comments
Closed

EscapeJs not works properly #164

MartkCz opened this issue Aug 2, 2017 · 3 comments

Comments

@MartkCz
Copy link
Contributor

@MartkCz MartkCz commented Aug 2, 2017

  • bug report? yes
  • version: v3.0.0.alpha1

Description

{block content}
	<canvas id="canvas"></canvas>

	<script>
		var data = {$data}; // ok
	</script>
{/block}

{block scripts}
	{include parent}
	<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.4.0/Chart.min.js" />

	<script>
		var data = {$data}; // error
		var labels = {$labels}; // error
	</script>
{/block}

Error: Array to string conversion. Because method escapeHtmlText is called:

php latte code:

	public $blocks = [
		'content' => 'blockContent',
		'scripts' => 'blockScripts',
	];

	public $blockTypes = [
		'content' => 'html',
		'scripts' => 'html',
	];


	function main()
	{
		extract($this->params);
		if ($this->getParentName()) return get_defined_vars();
		$this->renderBlock('content', get_defined_vars());
?>

<?php
		$this->renderBlock('scripts', get_defined_vars());
		return get_defined_vars();
	}


	function prepare()
	{
		extract($this->params);
		Nette\Bridges\ApplicationLatte\UIRuntime::initialize($this, $this->parentName, $this->blocks);
		
	}


	function blockContent($_args)
	{
		extract($_args);
?>
	<canvas id="canvas"></canvas>

	<script>
		var data = <?php echo LR\Filters::escapeJs($data) /* line 5 */ ?>;
	</script>
<?php
	}


	function blockScripts($_args)
	{
		extract($_args);
		$this->renderBlockParent('scripts', get_defined_vars());
?>
	<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.4.0/Chart.min.js"></script>

	<script>
		var data = <?php echo LR\Filters::escapeHtmlText($data) /* line 14 */ ?>;
		var labels = <?php echo LR\Filters::escapeHtmlText($labels) /* line 15 */ ?>;
	</script>
<?php
	}
@dg

This comment has been minimized.

Copy link
Member

@dg dg commented Aug 2, 2017

In your code is missing </script>

@MartkCz

This comment has been minimized.

Copy link
Contributor Author

@MartkCz MartkCz commented Aug 2, 2017

Where? Do you mean script after include parent? Short tags is not supported?

Thanks.

@dg

This comment has been minimized.

Copy link
Member

@dg dg commented Aug 2, 2017

Imho they are not supported by html.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.