Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[5.8] Fix recursive replacements in Str::replaceArray() #28338

Merged
merged 1 commit into from
Apr 25, 2019
Merged

[5.8] Fix recursive replacements in Str::replaceArray() #28338

merged 1 commit into from
Apr 25, 2019

Conversation

staudenmeir
Copy link
Contributor

Str::replaceArray() recursively replaces the search value if it appears in the replacements:

Str::replaceArray('?', ['foo?', 'bar'], '?, ?');

// expected: foo?, bar
// actual:   foobar, ?

Laravel uses the method in query exceptions to replace the ? placeholders with the actual bindings. This causes incorrect results if a binding contains a ?.

We can fix it splitting the string and gluing it back together.

Theoretically, this could be a breaking change for users who are relying on recursive replacements. But I don't a see case where you would want this behavior.

Fixes #28245.

@taylorotwell taylorotwell merged commit ed16959 into laravel:5.8 Apr 25, 2019
@staudenmeir staudenmeir deleted the replace-array branch April 25, 2019 22:07
@vlakoff
Copy link
Contributor

vlakoff commented May 16, 2019

I should review this code, but are you sure it works when the first replacement doesn't occur at the very beginning?

@vlakoff
Copy link
Contributor

vlakoff commented May 16, 2019

… or when the parts between the replacements are different.

If there is actually such breakage, the tests would have to be improved as well ;)

@vlakoff
Copy link
Contributor

vlakoff commented May 16, 2019

Just in case, refs #12259, though the previous code had the same problem.

@staudenmeir
Copy link
Contributor Author

@vlakoff Yes, these cases work.

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.

Bindings not correctly assigned in SQL exceptions
3 participants