1--TEST--
2Test base64_decode() function : basic functionality - padding and whitespace
3--SKIPIF--
4<?php if (!extension_loaded("json")) print "skip"; ?>
5--FILE--
6<?php
7/* Prototype  : proto string base64_decode(string str[, bool strict])
8 * Description: Decodes string using MIME base64 algorithm
9 * Source code: ext/standard/base64.c
10 * Alias to functions:
11 */
12
13echo "Test base64_decode (output as JSON):\n";
14$data = [
15	"", "=", "==", "===", "====",
16	"V", "V=", "V==", "V===", "V====",
17	"VV", "VV=", "VV==", "VV===", "VV====",
18	"VVV", "VVV=", "VVV==", "VVV===", "VVV====",
19	"VVVV", "VVVV=", "VVVV==", "VVVV===", "VVVV====",
20	"=V", "=VV", "=VVV",
21	"==V", "==VV", "==VVV",
22	"===V", "===VV", "===VVV",
23	"====V", "====VV", "====VVV",
24	"=VVV", "V=VV", "VV=V", "VVV=",
25	"=VVVV", "V=VVV", "VV=VV", "VVV=V", "VVVV=",
26	"=VVV=", "V=VV=", "VV=V=", "VVV==",
27	"\nVV", "V\nV", "VV\n",
28	"\nVV==", "V\nV==", "VV\n==", "VV=\n=", "VV==\n",
29	"*VV", "V*V", "VV*",
30	"*VV==", "V*V==", "VV*==", "VV=*=", "VV==*",
31	"\0VV==", "V\0V==", "VV\0==", "VV=\0=", "VV==\0",
32	"\0VVV==", "V\0VV==", "VV\0V==", "VVV\0==", "VVV=\0=", "VVV==\0",
33];
34foreach ($data as $a) {
35	$b = base64_decode($a, false);
36	$c = base64_decode($a, true);
37	printf("base64 %-16s non-strict %-8s strict %s\n", json_encode($a), json_encode($b), json_encode($c));
38}
39echo "Done\n";
40?>
41--EXPECTF--
42Test base64_decode (output as JSON):
43base64 ""               non-strict ""       strict ""
44base64 "="              non-strict ""       strict false
45base64 "=="             non-strict ""       strict false
46base64 "==="            non-strict ""       strict false
47base64 "===="           non-strict ""       strict false
48base64 "V"              non-strict ""       strict false
49base64 "V="             non-strict ""       strict false
50base64 "V=="            non-strict ""       strict false
51base64 "V==="           non-strict ""       strict false
52base64 "V===="          non-strict ""       strict false
53base64 "VV"             non-strict "U"      strict "U"
54base64 "VV="            non-strict "U"      strict false
55base64 "VV=="           non-strict "U"      strict "U"
56base64 "VV==="          non-strict "U"      strict false
57base64 "VV===="         non-strict "U"      strict false
58base64 "VVV"            non-strict "UU"     strict "UU"
59base64 "VVV="           non-strict "UU"     strict "UU"
60base64 "VVV=="          non-strict "UU"     strict false
61base64 "VVV==="         non-strict "UU"     strict false
62base64 "VVV===="        non-strict "UU"     strict false
63base64 "VVVV"           non-strict "UUU"    strict "UUU"
64base64 "VVVV="          non-strict "UUU"    strict false
65base64 "VVVV=="         non-strict "UUU"    strict false
66base64 "VVVV==="        non-strict "UUU"    strict false
67base64 "VVVV===="       non-strict "UUU"    strict false
68base64 "=V"             non-strict ""       strict false
69base64 "=VV"            non-strict "U"      strict false
70base64 "=VVV"           non-strict "UU"     strict false
71base64 "==V"            non-strict ""       strict false
72base64 "==VV"           non-strict "U"      strict false
73base64 "==VVV"          non-strict "UU"     strict false
74base64 "===V"           non-strict ""       strict false
75base64 "===VV"          non-strict "U"      strict false
76base64 "===VVV"         non-strict "UU"     strict false
77base64 "====V"          non-strict ""       strict false
78base64 "====VV"         non-strict "U"      strict false
79base64 "====VVV"        non-strict "UU"     strict false
80base64 "=VVV"           non-strict "UU"     strict false
81base64 "V=VV"           non-strict "UU"     strict false
82base64 "VV=V"           non-strict "UU"     strict false
83base64 "VVV="           non-strict "UU"     strict "UU"
84base64 "=VVVV"          non-strict "UUU"    strict false
85base64 "V=VVV"          non-strict "UUU"    strict false
86base64 "VV=VV"          non-strict "UUU"    strict false
87base64 "VVV=V"          non-strict "UUU"    strict false
88base64 "VVVV="          non-strict "UUU"    strict false
89base64 "=VVV="          non-strict "UU"     strict false
90base64 "V=VV="          non-strict "UU"     strict false
91base64 "VV=V="          non-strict "UU"     strict false
92base64 "VVV=="          non-strict "UU"     strict false
93base64 "\nVV"           non-strict "U"      strict "U"
94base64 "V\nV"           non-strict "U"      strict "U"
95base64 "VV\n"           non-strict "U"      strict "U"
96base64 "\nVV=="         non-strict "U"      strict "U"
97base64 "V\nV=="         non-strict "U"      strict "U"
98base64 "VV\n=="         non-strict "U"      strict "U"
99base64 "VV=\n="         non-strict "U"      strict "U"
100base64 "VV==\n"         non-strict "U"      strict "U"
101base64 "*VV"            non-strict "U"      strict false
102base64 "V*V"            non-strict "U"      strict false
103base64 "VV*"            non-strict "U"      strict false
104base64 "*VV=="          non-strict "U"      strict false
105base64 "V*V=="          non-strict "U"      strict false
106base64 "VV*=="          non-strict "U"      strict false
107base64 "VV=*="          non-strict "U"      strict false
108base64 "VV==*"          non-strict "U"      strict false
109base64 "\u0000VV=="     non-strict "U"      strict false
110base64 "V\u0000V=="     non-strict "U"      strict false
111base64 "VV\u0000=="     non-strict "U"      strict false
112base64 "VV=\u0000="     non-strict "U"      strict false
113base64 "VV==\u0000"     non-strict "U"      strict false
114base64 "\u0000VVV=="    non-strict "UU"     strict false
115base64 "V\u0000VV=="    non-strict "UU"     strict false
116base64 "VV\u0000V=="    non-strict "UU"     strict false
117base64 "VVV\u0000=="    non-strict "UU"     strict false
118base64 "VVV=\u0000="    non-strict "UU"     strict false
119base64 "VVV==\u0000"    non-strict "UU"     strict false
120Done
121