php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #53319 strip_tags() may strip '<br />' incorrectly
Submitted: 2010-11-16 01:22 UTC Modified: 2011-02-10 17:09 UTC
From: Ray dot Paseur at Gmail dot com Assigned: vrana (profile)
Status: Closed Package: Strings related
PHP Version: 5.3.3 OS: Linux
Private report: No CVE-ID: None
 [2010-11-16 01:22 UTC] Ray dot Paseur at Gmail dot com
Description:
------------
---
From manual page: http://www.php.net/function.strip-tags#Return Values
---


Test script:
---------------
<?php // RAY_strip_tags_anomaly.php
error_reporting(E_ALL);

// SELF-CLOSING TAGS WITH SPACES
$str = '<td>USD<br /><br />CDN</td>';
$new = strip_tags($str);
echo $new; // Prints USDCDN

// TRY TO PRESERVE ALLOWABLE TAGS
$new = strip_tags($str, '<br />');
echo $new; // Prints USDCDN -- The break tag is not preserved

$new = strip_tags($str, '<br>');
echo $new; // Prints USD<br /><br />CDN

// SELF-CLOSING TAGS WITHOUT SPACES
$str = '<td>USD<br/><br/>CDN</td>';
$new = strip_tags($str, '<br/>');
echo $new; // Prints USD<br/><br/>CDN


Expected result:
----------------
strip_tags() should preserve the allowable_tags

Actual result:
--------------
strip_tags did not always preserve the allowable_tags

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-11-16 23:16 UTC] felipe@php.net
Automatic comment from SVN on behalf of felipe
Revision: http://svn.php.net/viewvc/?view=revision&amp;revision=305418
Log: - Fixed bug #53319 (strip_tags() may strip '&lt;br /&gt;' incorrectly)
 [2010-11-16 23:21 UTC] felipe@php.net
-Status: Open +Status: To be documented
 [2010-11-16 23:21 UTC] felipe@php.net
I've fixed the bug related to '<br>' is stripping <br/> in the string.

About strip_tags($str, '<br/>'): The allowed tags should not contains slash char.
This must be documented though.
 [2010-11-16 23:22 UTC] felipe@php.net
-Summary: Strip_tags() may strip '<br />' incorrectly +Summary: strip_tags() may strip '<br />' incorrectly
 [2010-11-17 03:01 UTC] Ray dot Paseur at Gmail dot com
Thanks, Felipe!
 [2011-02-10 17:09 UTC] vrana@php.net
Automatic comment from SVN on behalf of vrana
Revision: http://svn.php.net/viewvc/?view=revision&amp;revision=308213
Log: Beware slashes (doc bug #53319)
 [2011-02-10 17:09 UTC] vrana@php.net
-Status: To be documented +Status: Closed -Assigned To: +Assigned To: vrana
 [2011-02-10 17:09 UTC] vrana@php.net
This bug has been fixed in the documentation's XML sources. Since the
online and downloadable versions of the documentation need some time
to get updated, we would like to ask you to be a bit patient.

Thank you for the report, and for helping us make our documentation better.


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Mar 19 06:01:30 2024 UTC