HEX
Server: nginx/1.24.0
System: Linux localhost 5.15.0-46-generic #49-Ubuntu SMP Thu Aug 4 18:03:25 UTC 2022 x86_64
User: www (1000)
PHP: 8.3.27
Disabled: passthru,exec,system,putenv,chroot,chgrp,chown,shell_exec,popen,proc_open,pcntl_exec,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,imap_open,apache_setenv
Upload Files
File: /www/server/php/83/src/ext/mbstring/tests/uuencode_encoding.phpt
--TEST--
Temporary test of mbstring's UUEncode 'encoding'
--EXTENSIONS--
mbstring
--FILE--
<?php
srand(1000); // Make results consistent

/* Using mbstring to convert strings from UUEncode has already been deprecated
 * So this test should be removed when the UUEncode 'encoding' is */
error_reporting(E_ALL & ~E_DEPRECATED);

function testConversion($uuencode, $raw) {
  $converted = mb_convert_encoding($uuencode, '8bit', 'UUENCODE');
  if ($converted !== $raw)
    die('Expected "' . $uuencode . '" to convert to ' . bin2hex($raw) . '; actually got ' . bin2hex($converted));
  $converted = mb_convert_encoding($raw, 'UUENCODE', '8bit');
  if ($converted !== $uuencode)
    die('Expected ' . bin2hex($raw) . ' to convert to "' . $uuencode . '"; actually got "' . $converted . '"');
}

testConversion('', '');

/* mbstring's uuencode requires the user to strip off the terminating "`\nend\n" */

testConversion("begin 0644 filename\n#0V%T\n", 'Cat');
testConversion("begin 0644 filename\n::'1T<#HO+W=W=RYW:6MI<&5D:6\$N;W)G#0H`\n", "http://www.wikipedia.org\r\n");
testConversion("begin 0644 filename\n#`0(#\n", "\x01\x02\x03");
testConversion("begin 0644 filename\n$`0(#\"@``\n", "\x01\x02\x03\n");

function testRoundTrip($data) {
  $encoded = mb_convert_encoding($data, 'UUENCODE', '8bit');
  $decoded = mb_convert_encoding($encoded, '8bit', 'UUENCODE');
  if ($data !== $decoded)
    die("Round-trip failed! Expected " . bin2hex($data) . " to round-trip; actually got " . bin2hex($decoded));
}

for ($iterations = 0; $iterations < 500; $iterations++) {
  $strlen = rand(1, 300);
  $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
  $randstring = '';
  for ($i = 0; $i < $strlen; $i++) {
      $randstring .= $characters[rand(0, strlen($characters) - 1)];
  }
  testRoundTrip($randstring);
}

echo "Done!\n";
?>
--EXPECTF--
Done!