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