1--TEST--
2Test htmlspecialchars_decode() function : usage variations - binary safe
3--FILE--
4<?php
5/* Prototype  : string htmlspecialchars_decode(string $string [, int $quote_style])
6 * Description: Convert special HTML entities back to characters
7 * Source code: ext/standard/html.c
8*/
9
10/*
11 * testing whether htmlspecialchars_decode() is binary safe or not
12*/
13
14echo "*** Testing htmlspecialchars_decode() : usage variations ***\n";
15
16//various string inputs
17$strings = array (
18  "\tHello \$world ".chr(0)."\&!)The big brown fox jumped over the\t\f lazy dog\v\n",
19  "\tHello \"world\"\t\v \0 This is a valid\t string",
20  "This converts\t decimal to \$string".decbin(65)."Hello world",
21  b"This is a binary\t \v\fstring"
22);
23
24//loop through the strings array to check if htmlspecialchars_decode() is binary safe
25$iterator = 1;
26foreach($strings as $value) {
27      echo "-- Iteration $iterator --\n";
28      if ($iterator < 4) {
29      	var_dump( htmlspecialchars_decode($value) );
30      } else {
31      	var_dump( bin2hex(htmlspecialchars_decode($value)));
32      }
33
34      $iterator++;
35}
36
37echo "Done";
38?>
39--EXPECTF--
40*** Testing htmlspecialchars_decode() : usage variations ***
41-- Iteration 1 --
42string(65) "	Hello $world �\&!)The big brown fox jumped over the	 lazy dog
43"
44-- Iteration 2 --
45string(42) "	Hello "world"	 � This is a valid	 string"
46-- Iteration 3 --
47string(51) "This converts	 decimal to $string1000001Hello world"
48-- Iteration 4 --
49string(52) "5468697320697320612062696e61727909200b0c737472696e67"
50Done
51