-
Notifications
You must be signed in to change notification settings - Fork 3
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
Fix some WP unit test errors #32
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh boy 🙈
As a side note, I found myself not trusting
$wpdb->prepare()
at all in my code. It seems weird to the point where I just stitch strings myself. I'm curious if that was your experience, too. I wonder if we have an opportunity here to make it better for SQLite and, e.g., actually use prepared statements. Probably not, because$wpdb
is supposed to return a string here, but it would be cool if that was possible.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@adamziel I haven't explored
$wpdb->prepare()
in depth yet, but I do think it's potentially problematic — not only possible performance problems (roundtrips to MySQL server for escaping), but also the fact that it will consume any input, no matter whether it's a valid query or not, which may lead to misuse. And on top of that, you have things like this, which make me even less confident about that approach.Considering this, I think WordPress deserves better, and maybe we could apply our learnings from implementing the SQLite driver, prototype a Postgres driver, and then see what improvements we could propose upstream.
As for what we can do with the SQLite driver itself, we only control the
_real_escape
WPDB method. I can see that historically, it seems to calladdslashes
, which I think we should replace with PDO->quote(), which should have no roundtrip cost since it's just a method call with SQLite. I'll check if using that breaks any tests.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, I realized the
addslashes
part is correct because in that place, we emulate MySQL escaping, while escaping for SQLite is done later, when translating the literals.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Escaping with slashes is difficult when we don't know the encoding of the input string. Is the byte 34 a double quote? Or is it a part of a multibyte character that we didn't recognize? Maybe we could call the method
bind_utf8_string()
and drop support for other encodings, then it's easy. I've been playing with escaping viabin2hex($string)
in php andUNHEX()
in the query. It's more computations, but it may still be faster than relying on real escape.