bug43840.phpt 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. --TEST--
  2. Test mb_strpos() function : mb_strpos bounds check is byte count rather than a character count
  3. --SKIPIF--
  4. <?php
  5. extension_loaded('mbstring') or die('skip');
  6. function_exists('mb_strpos') or die("skip mb_strpos() is not available in this build");
  7. ?>
  8. --FILE--
  9. <?php
  10. /* Prototype : int mb_strpos(string $haystack, string $needle [, int $offset [, string $encoding]])
  11. * Description: Find position of first occurrence of a string within another
  12. * Source code: ext/mbstring/mbstring.c
  13. */
  14. /*
  15. * mb_strpos bounds check is byte count rather than a character count:
  16. * The multibyte string should be returning the same results as the ASCII string.
  17. * Multibyte string was not returning error message until offset was passed the
  18. * byte count of the string. Should return error message when passed character count.
  19. */
  20. $offsets = array(20, 21, 22, 53, 54);
  21. $string_mb = base64_decode('5pel5pys6Kqe44OG44Kt44K544OI44Gn44GZ44CCMDEyMzTvvJXvvJbvvJfvvJjvvJnjgII=');
  22. $needle = base64_decode('44CC');
  23. foreach($offsets as $i) {
  24. echo "\n-- Offset is $i --\n";
  25. echo "--Multibyte String:--\n";
  26. var_dump( mb_strpos($string_mb, $needle, $i, 'UTF-8') );
  27. echo"--ASCII String:--\n";
  28. var_dump(mb_strpos(b'This is na English ta', b'a', $i));
  29. }
  30. ?>
  31. --EXPECTF--
  32. -- Offset is 20 --
  33. --Multibyte String:--
  34. int(20)
  35. --ASCII String:--
  36. int(20)
  37. -- Offset is 21 --
  38. --Multibyte String:--
  39. bool(false)
  40. --ASCII String:--
  41. bool(false)
  42. -- Offset is 22 --
  43. --Multibyte String:--
  44. Warning: mb_strpos(): Offset not contained in string in %s on line %d
  45. bool(false)
  46. --ASCII String:--
  47. Warning: mb_strpos(): Offset not contained in string in %s on line %d
  48. bool(false)
  49. -- Offset is 53 --
  50. --Multibyte String:--
  51. Warning: mb_strpos(): Offset not contained in string in %s on line %d
  52. bool(false)
  53. --ASCII String:--
  54. Warning: mb_strpos(): Offset not contained in string in %s on line %d
  55. bool(false)
  56. -- Offset is 54 --
  57. --Multibyte String:--
  58. Warning: mb_strpos(): Offset not contained in string in %s on line %d
  59. bool(false)
  60. --ASCII String:--
  61. Warning: mb_strpos(): Offset not contained in string in %s on line %d
  62. bool(false)