Skip to content

Commit 9aa4b2b

Browse files
committed
Add tests to document behavior of UTF7-IMAP conversion in obscure corner case
These unit tests cover situations which were not previously tested by the mbstring test suite. Adding them will make the test suite more complete. To be specific, the 'obscure' case which we are now testing is: what happens when the first half of a surrogate pair appears at end of an improperly terminated Base64 section in UTF7-IMAP text?
1 parent a57fdea commit 9aa4b2b

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

ext/mbstring/tests/utf7imap_encoding.phpt

+11-3
Original file line numberDiff line numberDiff line change
@@ -147,9 +147,17 @@ identifyInvalidString("&" . mBase64($doubleChar . $testString) . "-", 'UTF7-IMAP
147147

148148
/* 3. The first half of a surrogate pair could come at the end of the string, */
149149
$testString = mb_convert_encoding("\x00\x01\x04\x00", 'UTF-16BE', 'UTF-32BE');
150-
identifyInvalidString("&" . mBase64(substr($testString, 0, 2)) . "-", 'UTF7-IMAP');
151-
identifyInvalidString("&" . mBase64($singleChar . substr($testString, 0, 2)) . "-", 'UTF7-IMAP');
152-
identifyInvalidString("&" . mBase64($singleChar . $singleChar . substr($testString, 0, 2)) . "-", 'UTF7-IMAP');
150+
testInvalid("&" . mBase64(substr($testString, 0, 2)) . "-", "%");
151+
testInvalid("&" . mBase64($singleChar . substr($testString, 0, 2)) . "-", "\x01%");
152+
testInvalid("&" . mBase64($singleChar . $singleChar . substr($testString, 0, 2)) . "-", "\x01\x01%");
153+
/* ...and the string could even be improperly terminated... */
154+
testInvalid("&" . mBase64(substr($testString, 0, 2)), "%%");
155+
testInvalid("&" . mBase64($singleChar . substr($testString, 0, 2)), "\x01%%");
156+
/* NOTE: We currently don't check for trailing first half of surrogate pair when the string
157+
* abruptly ends after a group of 3 Base64-encoded codepoints... that's why we only emit one
158+
* error marker here for the incorrect termination of Base64 section and no error marker
159+
* for the trailing first half of surrogate pair */
160+
testInvalid("&" . mBase64($singleChar . $singleChar . substr($testString, 0, 2)), "\x01\x01%");
153161

154162
/* 4. Or, it could have an odd number of bytes in it! */
155163
$testString = utf16BE("ドーナツ");

0 commit comments

Comments
 (0)