yiisoft / yii2-redis

Yii 2 Redis extension.
http://www.yiiframework.com
BSD 3-Clause "New" or "Revised" License
452 stars 183 forks source link

If the query condition field is binary and not the primary key, error will be reported under some binary cases. #251

Open vistart opened 2 years ago

vistart commented 2 years ago

What steps will reproduce the problem?

https://github.com/vistart/yii2-redis/blob/master/tests/data/ar/CustomerBinary.php https://github.com/vistart/yii2-redis/blob/master/tests/data/ar/CustomerBinaryQuery.php

I modify the Customer class and added a guid field without modifying the primary key.

Then in ActiveRecordTest, save an instance of the CustomeryBinary and assign the guid to the binary form of "51a4e62e-1b1a-56c9-e9e5-9efe21f55276".

When testing the find() based on the guid value, it was found that the value was escaped in the buildHashCondition() method. The escaped result is inconsistent with the saved result.

The test results are as follows: https://github.com/vistart/yii2-redis/runs/7493880767

All modifications are as follows: https://github.com/yiisoft/yii2-redis/compare/master...vistart:yii2-redis:master

If the primary key is a binary value, this error will not be occurred because the finding process does not go through the escaping. But if the primary key is a composite fields, which contains a binary field, this error will still be triggered.

What's expected?

Can use non-primary key binary values as query conditions.

What do you get instead?

If it is a binary value, it should not be escaped.

Additional info

Q A
Yii vesion 2.0.0 or later
yii2-redis version 2.0.0 or later
PHP version 5.4 ~ 8.1
Operating system All
samdark commented 2 years ago

Do you have time for a pull request?

vistart commented 2 years ago

Do you have time for a pull request?

Next I will think carefully about how to solve this problem. It may take a few days.

vistart commented 2 years ago

The only way I can think of now is to give up escaping \032.

vistart commented 1 year ago

Bumps!