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

$input->getHtml() is stripping all HTML tags #12610

Closed
machadoug opened this issue Oct 28, 2016 · 2 comments
Closed

$input->getHtml() is stripping all HTML tags #12610

machadoug opened this issue Oct 28, 2016 · 2 comments

Comments

@machadoug
Copy link

machadoug commented Oct 28, 2016

I'm creating a component and I've stumbled upon an issue with the JFactory::getApplication()->input->post->get($this->alias,'','HTML'); code. It is stripping all tags.

Steps to reproduce the issue

In Joomla Administrator and in the front-end area I have performed a very simple test case using a simple textarea and an editor plugin and I got the same results.

In my form I have for example:

<form action="<?php echo JRoute::_( 'index.php?option=com_mycomponent&view=myview&id=1');" method="post" name="adminForm" id="adminForm" class="form-validate">
    <textarea name="test"></textarea>
</form>

I enter some valid html code in the textarea, for example:
<p>TEST</p>

In the model or in the controller or in the view I use the code:
var_dump(JFactory::getApplication()->input->post->get('test','','HTML') );

Expected result

<p>TEST</p>

Actual result

TEST

System information (as much as possible)

PHP Built On Linux 4.4.0-45-generic #66-Ubuntu SMP Wed Oct 19 14:12:37 UTC 2016 x86_64
Database Version 5.7.16-0ubuntu0.16.04.1
Database Collation utf8mb4_general_ci
Database Connection Collation utf8mb4_general_ci
PHP Version 7.0.8-0ubuntu0.16.04.3
Web Server Apache/2.4.18 (Ubuntu)
WebServer to PHP Interface apache2handler
Joomla! Version Joomla! 3.6.4 Stable [ Noether ] 21-October-2016 16:33 GMT
Joomla! Platform Version Joomla Platform 13.1.0 Stable [ Curiosity ] 24-Apr-2013 00:00 GMT
User Agent Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.71 Safari/537.36

Additional comments

If I get the desired HTML if I use:
JFactory::getApplication()->input->post->get('test','','RAW');
OR
JRequest::getVar('test', '', 'default', 'none',4))

Text Filter Settings in Joomla Global Configuration is set to No Filtering;

I'm not using JForm class.

@ggppdk
Copy link
Contributor

ggppdk commented Oct 28, 2016

There is no bug ... see below

'HTML' is plain text that allows HTML entities
'STRING' is plain text that decodes HTML entities and then strips the created tags

'HTML' was maybe a bad name choice ?,

  • that has caused confusion to many first time joomla develepers before you
  • but there is no bug

what you need is below (please test them, since i may have written something wrongly)

// Allow safe HTML ... but also decode HTML special characters before filtering
// Decoding allows removal of e.g. &lt;badtag&gt; ... &lt;/badtag&gt;
$v = JFactory::getApplication()->input->post->get('test','','RAW');
$safeHtmlFilter = JFilterInput::getInstance(null, null, 1, 1);
$v = $safeHtmlFilter->clean($v, 'string');

// Allow safe HTML ... and allow ANY HTML if encoded, e.g. allows &lt;i&gt; ... &lt;/i&gt;
$v = JFactory::getApplication()->input->post->get('test','','RAW');
$safeHtmlFilter = JFilterInput::getInstance(null, null, 1, 1);
$v = $safeHtmlFilter->clean($v, 'html');

// Filter according to user group Text Filters
$v = JFactory::getApplication()->input->post->get('test','','RAW');
$v = JComponentHelper::filterText($v);

@machadoug
Copy link
Author

@ggppdk Thanks for clarifying it for me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants