php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #78364 strip_tags should not remove \x00
Submitted: 2019-08-01 21:50 UTC Modified: 2019-08-02 00:42 UTC
Votes:2
Avg. Score:4.0 ± 1.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: bkfake-php at yahoo dot com Assigned:
Status: Open Package: Strings related
PHP Version: 7.3.8 OS: osx
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please — but make sure to vote on the bug!
Your email address:
MUST BE VALID
Solve the problem:
22 + 40 = ?
Subscribe to this entry?

 
 [2019-08-01 21:50 UTC] bkfake-php at yahoo dot com
Description:
------------
strip_tags strips the null character \x00 from the string
this is neither documented nor desired behavior

tested on v5.6.40 and 7.1.25 - 7.4.0beta1

Test script:
---------------
// outputs "where'd null go?"

$str = "hello\x00world";
$strAfter = strip_tags($str);
if ($str == $strAfter) {
    echo 'all is well';
} else {
    echo "where'd null go?";
}

Expected result:
----------------
null char should remain and output "all is well"

Actual result:
--------------
outputs "where'd null go?"

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2019-08-01 21:55 UTC] requinix@php.net
-Summary: strip_tags removes \x00 +Summary: strip_tags should not remove \x00 -Type: Bug +Type: Feature/Change Request -Package: Unknown/Other Function +Package: Strings related
 [2019-08-01 21:55 UTC] requinix@php.net
Undocumented? Are you sure about that?
 [2019-08-01 21:57 UTC] peehaa@php.net
-Status: Open +Status: Not a bug
 [2019-08-01 21:57 UTC] peehaa@php.net
This is clearly documented.

https://www.php.net/manual/en/function.trim.php
 [2019-08-01 21:58 UTC] peehaa@php.net
Sorry Damien you were too fast again :-)

Want to change it back to FR?
 [2019-08-01 22:17 UTC] requinix@php.net
-Status: Not a bug +Status: Open
 [2019-08-01 22:17 UTC] requinix@php.net
:)

Doing some research, I see HTML 5 allows NULs sometimes, but I can't tell how HTML 4 feels about it. If there was a particular reason strip_tags removed them then the behavior should probably stay, but otherwise I think it's a (undoubtedly rare) edge case that should be fine to remove.
 [2019-08-02 00:42 UTC] bkfake-php at yahoo dot com
In my case I'm working with "plain text" that may have had html tags added somewhere upstream..
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 19 20:01:29 2024 UTC