Skip to content

Commit

Permalink
[update] Improve regex for matching column name.
Browse files Browse the repository at this point in the history
  • Loading branch information
Angelaon committed Jul 9, 2021
1 parent bc17bcc commit 2119ecb
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/Medoo.php
Original file line number Diff line number Diff line change
Expand Up @@ -792,14 +792,14 @@ protected function columnPush(&$columns, array &$map, bool $root, bool $isJoin =
} elseif ($isArrayValue) {
$stack[] = $this->columnPush($value, $map, false, $isJoin);
} elseif (!$isIntKey && $raw = $this->buildRaw($value, $map)) {
preg_match('/(?<column>[\p{N}\p{L}\-_\.]+)(\s*\[(?<type>(String|Bool|Int|Number))\])?/u', $key, $match);
preg_match('/(?<column>[\p{L}_][\p{L}\p{N}@$#\-_\.]*)(\s*\[(?<type>(String|Bool|Int|Number))\])?/u', $key, $match);
$stack[] = "{$raw} AS {$this->columnQuote($match['column'])}";
} elseif ($isIntKey && is_string($value)) {
if ($isJoin && strpos($value, '*') !== false) {
throw new InvalidArgumentException('Cannot use table.* to select all columns while joining table.');
}

preg_match('/(?<column>[\p{N}\p{L}\-_\.]+)(?:\s*\((?<alias>.+)\))?(?:\s*\[(?<type>(?:String|Bool|Int|Number|Object|JSON))\])?/u', $value, $match);
preg_match('/(?<column>[\p{L}_][\p{L}\p{N}@$#\-_\.]*)(?:\s*\((?<alias>[\p{L}_][\p{L}\p{N}@$#\-_]*)\))?(?:\s*\[(?<type>(?:String|Bool|Int|Number|Object|JSON))\])?/u', $value, $match);

$columnString = '';

Expand Down Expand Up @@ -856,7 +856,7 @@ protected function dataImplode(array $data, array &$map, string $conjunctor): st
$isIndex = is_int($key);

preg_match(
'/([\p{N}\p{L}\-_\.]+)(\[(?<operator>\>\=?|\<\=?|\!|\<\>|\>\<|\!?~|REGEXP)\])?([\p{N}\p{L}\-_\.]+)?/u',
'/([\p{L}_][\p{L}\p{N}@$#\-_\.]*)(\[(?<operator>\>\=?|\<\=?|\!|\<\>|\>\<|\!?~|REGEXP)\])?([\p{L}_][\p{L}\p{N}@$#\-_\.]*)?/u',
$isIndex ? $value : $key,
$match
);
Expand Down

0 comments on commit 2119ecb

Please sign in to comment.