Ver código fonte

Update : table match exp

朱金辉 2 anos atrás
pai
commit
d2329d117f
1 arquivos alterados com 7 adições e 1 exclusões
  1. 7 1
      src/Driver/Base.php

+ 7 - 1
src/Driver/Base.php

@@ -842,8 +842,14 @@ class Base
     protected function getTableAlias($name)
     {
         if (!is_string($name) || (
+            // table
             !preg_match("/^[a-zA-Z_]+[a-zA-Z0-9_]{0,}$/", $name) &&
-            !preg_match("/^`[a-zA-Z_]+[a-zA-Z0-9_]{0,}`$/", $name))
+            // `table`
+            !preg_match("/^`[a-zA-Z_]+[a-zA-Z0-9_]{0,}`$/", $name)) &&
+            // table alias
+            !preg_match("/^[a-zA-Z_]+[a-zA-Z0-9_]{0,}\s+[a-zA-Z]+[a-zA-Z0-9_]{0,}$/", $name) &&
+            // `table` alias
+            !preg_match("/^`[a-zA-Z_]+[a-zA-Z0-9_]{0,}`\s+[a-zA-Z]+[a-zA-Z0-9_]{0,}$/", $name)
         ) {
             if (gettype($name) == 'string') {
                 throw new TableException("表名不能包含怪字符且不能以数字开头");