Skip to content

Conversation

@bookin
Copy link

@bookin bookin commented Feb 27, 2019

If one of parameters have a ? symbol in the text, preg_replace can work incorrectly, because just looking for any ? symbol

If one of parameters have a `?` symbol in the text, `preg_replace` can work incorrectly, because just looking for any `?` symbol
$sql = preg_replace(
'/(' . (is_int($key) ? '\?' : ':' . $key) . ')/i',
$this->getTypedParam($key),
'/(' . (is_int($key) ? '\?([,\)])' : ':' . $key) . ')/i',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what do you think about this expr: \?([,\)]|\s,|\s\)) for resolve next case with whitespace character: '? , ? ) ?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't seen this situation, but yes, we can add just spaces

Suggested change
'/(' . (is_int($key) ? '\?([,\)])' : ':' . $key) . ')/i',
'/(' . (is_int($key) ? '\?(\s?[,\)])' : ':' . $key) . ')/i',

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Anyway, it don't help if we will have ?, in the text :)

@bookin
Copy link
Author

bookin commented Feb 27, 2019

Seems you have a solution in the $hasZeroIndex part, sorry, I use an older version and can not test code to change all to use one method to both ways.

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