bug43840.phpt 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. --TEST--
  2. Test mb_strpos() function : mb_strpos bounds check is byte count rather than a character count
  3. --EXTENSIONS--
  4. mbstring
  5. --FILE--
  6. <?php
  7. /*
  8. * mb_strpos bounds check is byte count rather than a character count:
  9. * The multibyte string should be returning the same results as the ASCII string.
  10. * Multibyte string was not returning error message until offset was passed the
  11. * byte count of the string. Should return error message when passed character count.
  12. */
  13. $offsets = array(20, 21, 22, 53, 54);
  14. $string_mb = base64_decode('5pel5pys6Kqe44OG44Kt44K544OI44Gn44GZ44CCMDEyMzTvvJXvvJbvvJfvvJjvvJnjgII=');
  15. $needle = base64_decode('44CC');
  16. foreach($offsets as $i) {
  17. echo "\n-- Offset is $i --\n";
  18. echo "--Multibyte String:--\n";
  19. try {
  20. var_dump( mb_strpos($string_mb, $needle, $i, 'UTF-8') );
  21. } catch (\ValueError $e) {
  22. echo $e->getMessage() . \PHP_EOL;
  23. }
  24. echo"--ASCII String:--\n";
  25. try {
  26. var_dump(mb_strpos('This is na English ta', 'a', $i));
  27. } catch (\ValueError $e) {
  28. echo $e->getMessage() . \PHP_EOL;
  29. }
  30. }
  31. ?>
  32. --EXPECT--
  33. -- Offset is 20 --
  34. --Multibyte String:--
  35. int(20)
  36. --ASCII String:--
  37. int(20)
  38. -- Offset is 21 --
  39. --Multibyte String:--
  40. bool(false)
  41. --ASCII String:--
  42. bool(false)
  43. -- Offset is 22 --
  44. --Multibyte String:--
  45. mb_strpos(): Argument #3 ($offset) must be contained in argument #1 ($haystack)
  46. --ASCII String:--
  47. mb_strpos(): Argument #3 ($offset) must be contained in argument #1 ($haystack)
  48. -- Offset is 53 --
  49. --Multibyte String:--
  50. mb_strpos(): Argument #3 ($offset) must be contained in argument #1 ($haystack)
  51. --ASCII String:--
  52. mb_strpos(): Argument #3 ($offset) must be contained in argument #1 ($haystack)
  53. -- Offset is 54 --
  54. --Multibyte String:--
  55. mb_strpos(): Argument #3 ($offset) must be contained in argument #1 ($haystack)
  56. --ASCII String:--
  57. mb_strpos(): Argument #3 ($offset) must be contained in argument #1 ($haystack)