diff --git a/e107_handlers/db_verify_class.php b/e107_handlers/db_verify_class.php index 8a991a0731..a572f021c4 100755 --- a/e107_handlers/db_verify_class.php +++ b/e107_handlers/db_verify_class.php @@ -1065,9 +1065,8 @@ function getFields($data, $print = false) */ function getIndex($data, $print = false) { - // $regex = "/(?:(PRIMARY|UNIQUE|FULLTEXT))?[\s]*?KEY (?: ?`?([\w]*)`?)[\s]* ?(?:\([\s]?`?([\w,]*[\s]?)`?\))?,?/i"; - // $regex = "/(?:(PRIMARY|UNIQUE|FULLTEXT|FOREIGN))?[\s]*?KEY (?: ?`?([\w]*)`?)[\s]* ?(?:\([\s]?([\w\s,`]*[\s]?)`?\))?,?/i"; - $regex = "/(?:(PRIMARY|UNIQUE|FULLTEXT|FOREIGN))?[\s]*?(INDEX|KEY) (?: ?`?([\w]*)`?)[\s]* ?(?:\([\s]?([\w\s,`]*[\s]?)`?\))?,?/i"; + $regex = "/(PRIMARY|UNIQUE|FULLTEXT|FOREIGN)?[\s]*?(INDEX|KEY)[\s]*(?:`?([\w]*)`?)?[\s]*?\(`?([\w]+)`?(?:\s*\(\d+\))?(?:\s*(ASC|DESC))?\)[\s]*,?/i"; + preg_match_all($regex,$data,$m); if (count($m) > 0) diff --git a/e107_tests/tests/unit/db_verifyTest.php b/e107_tests/tests/unit/db_verifyTest.php index ecce2a5dbb..b2b847b578 100644 --- a/e107_tests/tests/unit/db_verifyTest.php +++ b/e107_tests/tests/unit/db_verifyTest.php @@ -263,6 +263,53 @@ public function testGetIndex() $this->assertEquals($expected,$result); } + /** + * @see https://github.com/e107inc/e107/issues/5054 + */ + public function testGetIndexOptionalLengthAndSortOrder() + { + $data = << + array( + 'type' => '', + 'keyname' => 'field1', + 'field' => 'field1', + ), + 'field2' => + array( + 'type' => '', + 'keyname' => 'field2', + 'field' => 'field2', + ), + 'field3' => + array( + 'type' => '', + 'keyname' => 'field3', + 'field' => 'field3', + ), + 'field4' => + array( + 'type' => '', + 'keyname' => 'field4', + 'field' => 'field4', + ), + ); + + $result = $this->dbv->getIndex($data); + $this->assertEquals($expected,$result); + } + /** * FIXME: This test has no assertions! */