Skip to content

Conversation

ctf0
Copy link
Contributor

@ctf0 ctf0 commented Jun 25, 2020

account for having a space between the key & value

account for having a space between the key & value
@ivanvermeyen
Copy link
Contributor

Hi, thanks for the pull.
I was trying to find out why it failed the tests.
Seems the middle wildcard would allow other locale keys to be between the required locale and the the value we're searching for... thus returning a false positive.
Dunno if there is another way except tacking on another where clause.

@ctf0
Copy link
Contributor Author

ctf0 commented Jun 25, 2020

i added the wildcard to be back compatible, but honestly i've never seen a json field without space between key & value, unless the user is saving the data with custom format.

otherwise we can remove the wildcard and add an empty space instead.

@ivanvermeyen
Copy link
Contributor

Hmm, I just checked one of my projects that use spatie/laravel-translatable and there is indeed a space.
Weird that there is no space in the test database.

@ivanvermeyen
Copy link
Contributor

Ok, I found the reason...

With spaces when you use a json field (MySQL > 5.7 only):

$table->json('name')->nullable();

Without spaces if you use a text field:

$table->text('name')->nullable();

PHP's json_encode function that is used by the laravel-translatable package doesn't use spaces.
Those seem to be added by MySQL if you use a json field.

@ctf0
Copy link
Contributor Author

ctf0 commented Jun 25, 2020

using json yes

@ivanvermeyen ivanvermeyen changed the title fix validation not working Support spaces between JSON key/value pairs Jun 25, 2020
@ivanvermeyen ivanvermeyen changed the title Support spaces between JSON key/value pairs Support spaces between JSON key/value Jun 25, 2020
@ivanvermeyen ivanvermeyen merged commit 6fb2df1 into codezero-be:master Jun 25, 2020
@ivanvermeyen
Copy link
Contributor

Until we find a better solution, the orWhere clause seems to do the trick...
Thanks for catching this, and for the pull request! 👍

@ctf0 ctf0 deleted the patch-1 branch June 25, 2020 18:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants