strip_tags bug or intended behavior?

Alan Nelson <[email protected]>
Newsgroups gmane.comp.php.general
Message-ID <DS7PR07MB83187B71E62A81C9D08712B89A582@DS7PR07MB8318.namprd07.prod.outlook.com>
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
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.