PCRE2_SPTR mark = NULL; /* Target for MARK name */
zval marks; /* Array of marks for PREG_PATTERN_ORDER */
pcre2_match_data *match_data;
- PCRE2_SIZE start_offset2;
+ PCRE2_SIZE start_offset2, orig_start_offset;
char *subject = ZSTR_VAL(subject_str);
size_t subject_len = ZSTR_LEN(subject_str);
}
}
- options = (pce->compile_options & PCRE2_UTF) && !is_known_valid_utf8(subject_str, start_offset2)
- ? 0 : PCRE2_NO_UTF_CHECK;
+ orig_start_offset = start_offset2;
+ options =
+ (pce->compile_options & PCRE2_UTF) && !is_known_valid_utf8(subject_str, orig_start_offset)
+ ? 0 : PCRE2_NO_UTF_CHECK;
/* Execute the regular expression. */
#ifdef HAVE_PCRE_JIT_SUPPORT
if (PCRE_G(error_code) == PHP_PCRE_NO_ERROR) {
/* If there was no error and we're in /u mode, remember that the string is valid UTF-8. */
- if ((pce->compile_options & PCRE2_UTF) && !ZSTR_IS_INTERNED(subject_str)) {
+ if ((pce->compile_options & PCRE2_UTF)
+ && !ZSTR_IS_INTERNED(subject_str) && orig_start_offset == 0) {
GC_ADD_FLAGS(subject_str, IS_STR_VALID_UTF8);
}
var_dump(preg_match($pattern, $text, $matches, 0, 1));
var_dump(preg_last_error() == PREG_BAD_UTF8_OFFSET_ERROR);
+echo "\n";
+
+$text = "VA\xff"; $text .= "LID";
+var_dump(preg_match($pattern, $text, $matches, 0, 4));
+var_dump(preg_match($pattern, $text, $matches, 0, 0));
+var_dump(preg_last_error() == PREG_BAD_UTF8_ERROR);
+
?>
--EXPECT--
int(0)
bool(false)
bool(true)
+
+int(1)
+bool(false)
+bool(true)