Commit 804aded5 by Klimov Paul

`yii\sphinx\Connection::escapeMatchValue()` fixed

parent 62fdaeec
...@@ -138,11 +138,10 @@ class Connection extends \yii\db\Connection ...@@ -138,11 +138,10 @@ class Connection extends \yii\db\Connection
*/ */
public function escapeMatchValue($str) public function escapeMatchValue($str)
{ {
$str = str_replace( return str_replace(
['\\', '/', '"', "'", '(', ')', '|', '-', '!', '@', '~', '&', '^', '$', '=', "\x00", "\n", "\r", "\x1a"], ['\\', "'", '/', '"', '(', ')', '|', '-', '!', '@', '~', '&', '^', '$', '=', "\x00", "\n", "\r", "\x1a"],
['\\\\', '\\/', '\\"', "\\'", '\\(', '\\)', '\\|', '\\-', '\\!', '\\@', '\\~', '\\&', '\\^', '\\$', '\\=', "\\x00", "\\n", "\\r", "\\x1a"], ['\\\\', "\\'", '\\\\/', '\\\\"', '\\\\(', '\\\\)', '\\\\|', '\\\\-', '\\\\!', '\\\\@', '\\\\~', '\\\\&', '\\\\^', '\\\\$', '\\\\=', "\\x00", "\\n", "\\r", "\\x1a"],
$str $str
); );
return str_replace('\\', '\\\\', $str);
} }
} }
...@@ -271,19 +271,42 @@ class QueryTest extends SphinxTestCase ...@@ -271,19 +271,42 @@ class QueryTest extends SphinxTestCase
} }
/** /**
* Data provider for [[testMatchSpecialCharValue()]]
* @return array test data
*/
public function dataProviderMatchSpecialCharValue()
{
return [
["'"],
['"'],
['@'],
['\\'],
['()'],
['\\' . "'"],
["\x00"],
["\n"],
["\r"],
["\x1a"]
];
}
/**
* @dataProvider dataProviderMatchSpecialCharValue
* @depends testRun * @depends testRun
* *
* @param string $char char to be tested
*
* @see https://github.com/yiisoft/yii2/issues/3668 * @see https://github.com/yiisoft/yii2/issues/3668
*/ */
public function testMatchSpecialCharValue() public function testMatchSpecialCharValue($char)
{ {
$connection = $this->getConnection(); $connection = $this->getConnection();
$query = new Query; $query = new Query;
$rows = $query->from('yii2_test_article_index') $rows = $query->from('yii2_test_article_index')
->match('about\"') ->match('about' . $char)
->all($connection); ->all($connection);
$this->assertNotEmpty($rows); $this->assertTrue(is_array($rows)); // no query error
} }
/** /**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment