mirror of
https://github.com/codeigniter4/CodeIgniter4.git
synced 2025-02-20 11:44:28 +08:00
refactor: use more strict result on preg_match_all() result
This commit is contained in:
parent
8e0bb04262
commit
82340aa1c7
@ -348,7 +348,7 @@ class CLI
|
||||
// return the prompt again if $input contain(s) non-numeric character, except a comma.
|
||||
// And if max from $options less than max from input,
|
||||
// it means user tried to access null value in $options
|
||||
if ($pattern === 0 || $maxOptions < $maxInput) {
|
||||
if ($pattern < 1 || $maxOptions < $maxInput) {
|
||||
static::error('Please select correctly.');
|
||||
CLI::newLine();
|
||||
|
||||
|
@ -663,7 +663,7 @@ class BaseBuilder
|
||||
} else {
|
||||
// Split multiple conditions
|
||||
// @TODO This does not parse `BETWEEN a AND b` correctly.
|
||||
if (preg_match_all('/\sAND\s|\sOR\s/i', $cond, $joints, PREG_OFFSET_CAPTURE)) {
|
||||
if (preg_match_all('/\sAND\s|\sOR\s/i', $cond, $joints, PREG_OFFSET_CAPTURE) >= 1) {
|
||||
$conditions = [];
|
||||
$joints = $joints[0];
|
||||
array_unshift($joints, ['', 0]);
|
||||
@ -3470,7 +3470,7 @@ class BaseBuilder
|
||||
'/' . implode('|', $this->pregOperators) . '/i',
|
||||
$str,
|
||||
$match
|
||||
) ? ($list ? $match[0] : $match[0][0]) : false;
|
||||
) >= 1 ? ($list ? $match[0] : $match[0][0]) : false;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -3501,7 +3501,7 @@ class BaseBuilder
|
||||
'/' . implode('|', $pregOperators) . '/i',
|
||||
$whereKey,
|
||||
$match
|
||||
) ? $match[0] : false;
|
||||
) >= 1 ? $match[0] : false;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -342,7 +342,7 @@ class Query implements QueryInterface, Stringable
|
||||
*/
|
||||
protected function matchSimpleBinds(string $sql, array $binds, int $bindCount, int $ml): string
|
||||
{
|
||||
if ($c = preg_match_all("/'[^']*'/", $sql, $matches)) {
|
||||
if ($c = preg_match_all("/'[^']*'/", $sql, $matches) >= 1) {
|
||||
$c = preg_match_all('/' . preg_quote($this->bindMarker, '/') . '/i', str_replace($matches[0], str_replace($this->bindMarker, str_repeat(' ', $ml), $matches[0]), $sql, $c), $matches, PREG_OFFSET_CAPTURE);
|
||||
|
||||
// Bind values' count must match the count of markers in the query
|
||||
|
@ -122,7 +122,7 @@ class Builder extends BaseBuilder
|
||||
$cond = ' ON ' . $cond;
|
||||
} else {
|
||||
// Split multiple conditions
|
||||
if (preg_match_all('/\sAND\s|\sOR\s/i', $cond, $joints, PREG_OFFSET_CAPTURE)) {
|
||||
if (preg_match_all('/\sAND\s|\sOR\s/i', $cond, $joints, PREG_OFFSET_CAPTURE) >= 1) {
|
||||
$conditions = [];
|
||||
$joints = $joints[0];
|
||||
array_unshift($joints, ['', 0]);
|
||||
|
@ -1031,7 +1031,7 @@ class Email
|
||||
|
||||
$unwrap = [];
|
||||
|
||||
if (preg_match_all('|\{unwrap\}(.+?)\{/unwrap\}|s', $str, $matches)) {
|
||||
if (preg_match_all('|\{unwrap\}(.+?)\{/unwrap\}|s', $str, $matches) >= 1) {
|
||||
for ($i = 0, $c = count($matches[0]); $i < $c; $i++) {
|
||||
$unwrap[] = $matches[1][$i];
|
||||
$str = str_replace($matches[0][$i], '{{unwrapped' . $i . '}}', $str);
|
||||
|
@ -131,7 +131,7 @@ if (! function_exists('entities_to_ascii')) {
|
||||
*/
|
||||
function entities_to_ascii(string $str, bool $all = true): string
|
||||
{
|
||||
if (preg_match_all('/\&#(\d+)\;/', $str, $matches)) {
|
||||
if (preg_match_all('/\&#(\d+)\;/', $str, $matches) >= 1) {
|
||||
for ($i = 0, $s = count($matches[0]); $i < $s; $i++) {
|
||||
$digits = (int) $matches[1][$i];
|
||||
$out = '';
|
||||
@ -195,7 +195,7 @@ if (! function_exists('word_censor')) {
|
||||
"\\1{$replacement}\\3",
|
||||
$str
|
||||
);
|
||||
} elseif (preg_match_all("/{$delim}(" . $badword . "){$delim}/i", $str, $matches, PREG_PATTERN_ORDER | PREG_OFFSET_CAPTURE)) {
|
||||
} elseif (preg_match_all("/{$delim}(" . $badword . "){$delim}/i", $str, $matches, PREG_PATTERN_ORDER | PREG_OFFSET_CAPTURE) >= 1) {
|
||||
$matches = $matches[1];
|
||||
|
||||
for ($i = count($matches) - 1; $i >= 0; $i--) {
|
||||
@ -351,7 +351,7 @@ if (! function_exists('word_wrap')) {
|
||||
// strip the entire chunk and replace it with a marker.
|
||||
$unwrap = [];
|
||||
|
||||
if (preg_match_all('|\{unwrap\}(.+?)\{/unwrap\}|s', $str, $matches)) {
|
||||
if (preg_match_all('|\{unwrap\}(.+?)\{/unwrap\}|s', $str, $matches) >= 1) {
|
||||
for ($i = 0, $c = count($matches[0]); $i < $c; $i++) {
|
||||
$unwrap[] = $matches[1][$i];
|
||||
$str = str_replace($matches[0][$i], '{{unwrapped' . $i . '}}', $str);
|
||||
|
@ -360,7 +360,7 @@ if (! function_exists('auto_link')) {
|
||||
$str,
|
||||
$matches,
|
||||
PREG_OFFSET_CAPTURE | PREG_SET_ORDER
|
||||
)
|
||||
) >= 1
|
||||
) {
|
||||
// Set our target HTML if using popup links.
|
||||
$target = ($popup) ? ' target="_blank"' : '';
|
||||
@ -387,7 +387,7 @@ if (! function_exists('auto_link')) {
|
||||
$str,
|
||||
$matches,
|
||||
PREG_OFFSET_CAPTURE
|
||||
)
|
||||
) >= 1
|
||||
) {
|
||||
foreach (array_reverse($matches[0]) as $match) {
|
||||
if (filter_var($match[0], FILTER_VALIDATE_EMAIL) !== false) {
|
||||
|
@ -98,7 +98,7 @@ class MemcachedHandler extends BaseHandler
|
||||
$this->savePath,
|
||||
$matches,
|
||||
PREG_SET_ORDER
|
||||
) === 0
|
||||
) < 1
|
||||
) {
|
||||
$this->memcached = null;
|
||||
$this->logger->error('Session: Invalid Memcached save path format: ' . $this->savePath);
|
||||
|
@ -96,7 +96,7 @@ class Typography
|
||||
|
||||
// HTML comment tags don't conform to patterns of normal tags, so pull them out separately, only if needed
|
||||
$htmlComments = [];
|
||||
if (str_contains($str, '<!--') && preg_match_all('#(<!\-\-.*?\-\->)#s', $str, $matches)) {
|
||||
if (str_contains($str, '<!--') && preg_match_all('#(<!\-\-.*?\-\->)#s', $str, $matches) >= 1) {
|
||||
for ($i = 0, $total = count($matches[0]); $i < $total; $i++) {
|
||||
$htmlComments[] = $matches[0][$i];
|
||||
$str = str_replace($matches[0][$i], '{@HC' . $i . '}', $str);
|
||||
|
@ -419,7 +419,7 @@ class Parser extends View
|
||||
* $matches[][0] is the raw match
|
||||
* $matches[][1] is the contents
|
||||
*/
|
||||
if (preg_match_all($pattern, $template, $matches, PREG_SET_ORDER)) {
|
||||
if (preg_match_all($pattern, $template, $matches, PREG_SET_ORDER) >= 1) {
|
||||
foreach ($matches as $match) {
|
||||
// Create a hash of the contents to insert in its place.
|
||||
$hash = md5($match[1]);
|
||||
@ -691,7 +691,7 @@ class Parser extends View
|
||||
* $matches[1] = all parameters string in opening tag
|
||||
* $matches[2] = content between the tags to send to the plugin.
|
||||
*/
|
||||
if (preg_match_all($pattern, $template, $matches, PREG_SET_ORDER) === 0) {
|
||||
if (preg_match_all($pattern, $template, $matches, PREG_SET_ORDER) < 1) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user