@@ -962,6 +962,7 @@ for ($i = 0; $i < 256; $i++) {
962
962
testValidString ('+ ' . encode ("\x12\x34" , 'UTF-16BE ' ) . '- ' , "\x00\x00\x12\x34" , 'UTF-7 ' , 'UTF-32BE ' );
963
963
testValidString ('+ ' . encode ("\x12\x34\x56\x78" , 'UTF-16BE ' ) . '- ' , "\x00\x00\x12\x34\x00\x00\x56\x78" , 'UTF-7 ' , 'UTF-32BE ' );
964
964
testValidString ('+ ' . encode ("\x12\x34\x56\x78\x00\x40" , 'UTF-16BE ' ) . '- ' , "\x00\x00\x12\x34\x00\x00\x56\x78\x00\x00\x00\x40" , 'UTF-7 ' , 'UTF-32BE ' );
965
+ testValidString ('+ ' . encode ("\xFF\xEE\xEE\xFF" , 'UTF-16BE ' ) . '- ' , "\x00\x00\xFF\xEE\x00\x00\xEE\xFF" , 'UTF-7 ' , 'UTF-32BE ' );
965
966
966
967
// Surrogate pair
967
968
testValidString ('+ ' . encode ("\x00\x01\x04\x00" , 'UTF-32BE ' ) . '- ' , "\x00\x01\x04\x00" , 'UTF-7 ' , 'UTF-32BE ' );
@@ -981,7 +982,7 @@ testValidString('+' . encode('AB', 'ASCII') . '-+' . encode('CD', 'ASCII') . '-'
981
982
testValidString ('+ ' . encode ('AB ' , 'ASCII ' ) . '-!+ ' . encode ('CD ' , 'ASCII ' ) . '- ' , "\x00A \x00B \x00! \x00C \x00D " , 'UTF-7 ' , 'UTF-16BE ' , false );
982
983
983
984
// + section terminated by a non-Base64 ASCII character which is NOT -
984
- for ($ i = 0 ; $ i < 128 ; $ i ++) {
985
+ for ($ i = 0 ; $ i < 128 ; $ i ++) {
985
986
if ($ i >= ord ('A ' ) && $ i <= ord ('Z ' ))
986
987
continue ;
987
988
if ($ i >= ord ('a ' ) && $ i <= ord ('z ' ))
@@ -994,22 +995,39 @@ for ($i = 0; $i < 128; $i++) {
994
995
testValidString ('+ ' . encode ("\x12\x34" , 'UTF-16BE ' ) . $ char , "\x00\x00\x12\x34\x00\x00\x00" . $ char , 'UTF-7 ' , 'UTF-32BE ' , false );
995
996
}
996
997
998
+ // Non-direct character followed by direct character
999
+ testValidString ('%A ' , '+ACU-A ' , 'ASCII ' , 'UTF-7 ' );
1000
+ testValidString ('%%A ' , '+ACUAJQ-A ' , 'ASCII ' , 'UTF-7 ' );
1001
+ testValidString ('%%%A ' , '+ACUAJQAl-A ' , 'ASCII ' , 'UTF-7 ' );
1002
+
997
1003
// Now let's see how UTF-7 can go BAD...
998
1004
999
1005
function rawEncode ($ str ) {
1000
1006
return str_replace ('= ' , '' , base64_encode ($ str ));
1001
1007
}
1002
1008
1009
+ // Totally bogus byte
1010
+ testInvalidString ("\xFF" , "% " , 'UTF-7 ' , 'UTF-8 ' );
1011
+ // Totally bogus codepoint... '+ACU-' is '%' in UTF-7'
1012
+ testInvalidString ("\x12\x34\x56\x78" , "+ACU- " , 'UTF-32BE ' , 'UTF-7 ' );
1013
+
1003
1014
// First, messed up UTF16 in + section
1004
1015
// Second half of surrogate pair coming first
1005
1016
testInvalidString ('+ ' . rawEncode ("\xDC\x01\xD8\x02" ) . '- ' , "\x00\x00\x00% \x00\x00\x00% " , 'UTF-7 ' , 'UTF-32BE ' );
1017
+ testInvalidString ('+ ' . rawEncode ("\x00. \xDC\x01\xD8\x02" ) . '- ' , "\x00\x00\x00. \x00\x00\x00% \x00\x00\x00% " , 'UTF-7 ' , 'UTF-32BE ' );
1018
+ testInvalidString ('+ ' . rawEncode ("\x00. \x00. \xDC\x01\xD8\x02" ) . '- ' , "\x00\x00\x00. \x00\x00\x00. \x00\x00\x00% \x00\x00\x00% " , 'UTF-7 ' , 'UTF-32BE ' );
1006
1019
1007
1020
// First half of surrogate pair not followed by second half
1008
1021
testInvalidString ('+ ' . rawEncode ("\xD8\x01\x00A " ) . '- ' , "\x00\x00\x00% \x00\x00\x00A " , 'UTF-7 ' , 'UTF-32BE ' );
1009
1022
testInvalidString ('+ ' . rawEncode ("\xD8\x01\xD9\x02" ) . '- ' , "\x00\x00\x00% \x00\x00\x00% " , 'UTF-7 ' , 'UTF-32BE ' );
1023
+ testInvalidString ('+ ' . rawEncode ("\x00. \xD8\x01\x00A " ) . '- ' , "\x00\x00\x00. \x00\x00\x00% \x00\x00\x00A " , 'UTF-7 ' , 'UTF-32BE ' );
1024
+ testInvalidString ('+ ' . rawEncode ("\x00. \xD8\x01\xD9\x02" ) . '- ' , "\x00\x00\x00. \x00\x00\x00% \x00\x00\x00% " , 'UTF-7 ' , 'UTF-32BE ' );
1025
+ testInvalidString ('+ ' . rawEncode ("\x00. \x00. \xD8\x01\x00A " ) . '- ' , "\x00\x00\x00. \x00\x00\x00. \x00\x00\x00% \x00\x00\x00A " , 'UTF-7 ' , 'UTF-32BE ' );
1026
+ testInvalidString ('+ ' . rawEncode ("\x00. \x00. \xD8\x01\xD9\x02" ) . '- ' , "\x00\x00\x00. \x00\x00\x00. \x00\x00\x00% \x00\x00\x00% " , 'UTF-7 ' , 'UTF-32BE ' );
1010
1027
1011
1028
// First half of surrogate pair appearing at end of string
1012
1029
testInvalidString ('+ ' . rawEncode ("\xD8\x01" ) . '- ' , "\x00\x00\x00% " , 'UTF-7 ' , 'UTF-32BE ' );
1030
+ testInvalidString ('+ ' . rawEncode ("\xD8\x01" ), "\x00\x00\x00% " , 'UTF-7 ' , 'UTF-32BE ' );
1013
1031
1014
1032
// Truncated string
1015
1033
testInvalidString ('+ ' . rawEncode ("\x01" ) . '- ' , "\x00\x00\x00% " , 'UTF-7 ' , 'UTF-32BE ' );
0 commit comments