strip_tags bug or intended behavior?

From: Date: Wed, 28 Feb 2024 20:04:06 +0000
Subject: strip_tags bug or intended behavior?
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-328381@lists.php.net to get a copy of this message
The Laravel framework has a test function called "assertSeeText" that looks for text in a rendered view. Internally it uses PHP's strip_tags function to filter out the text. I discovered that when the rendered view (and input string for strip_tags) contains minified JavaScript it often breaks. I'm torn on if this is a bug in PHP's strip_tags function - or a bad use case for strip_tags - and looking for opinions before opening a bug report on either project. Passing the below example into strip_tags fails because "n<a.length" in the JavaScript is interpreted as an opening tag. All content after "<a.length" is removed. Does this seem like a bug or intended behavior? On one hand it seems like a bug because this is valid HTML, but on the other hand strip_tags is not documented as supporting JavaScript or intended for it. ===== HTML EXAMPLE ===== <!DOCTYPE html> <html lang="en"> <head> <script> function test(a) { for(let n=0; n<a.length; n++){ console.log(a[n]); } }; test(['one', 'two']); </script> </head> <body> <p>content</p> </body> </html> ===== END HTML EXAMPLE ===== ===== OUTPUT FROM strip_tags ===== function test(a) { for(let n=0; n ===== END OUTPUT ===== Thanks, - Alan

« previous php.general (#328381) next »