-
Notifications
You must be signed in to change notification settings - Fork 11.5k
[10.x] Escaping functionality within the Grammar #46558
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
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
335cd96
grammars can escape values for safe embedding in sql queries
tpetry b3c68e7
moved escaping to connection, better escapes for many types
tpetry cd7ad50
styleci
tpetry 5df51bd
styleci
tpetry 8aafee8
type and doc improvements
tpetry c54339f
styleci
tpetry 8a489f6
null doctype missing
tpetry fca8e96
formatting
taylorotwell 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
<?php | ||
|
||
namespace Illuminate\Tests\Integration\Database\MySql; | ||
|
||
use RuntimeException; | ||
|
||
/** | ||
* @requires extension pdo_mysql | ||
* @requires OS Linux|Darwin | ||
*/ | ||
class EscapeTest extends MySqlTestCase | ||
{ | ||
public function testEscapeInt() | ||
{ | ||
$this->assertSame('42', $this->app['db']->escape(42)); | ||
$this->assertSame('-6', $this->app['db']->escape(-6)); | ||
} | ||
|
||
public function testEscapeFloat() | ||
{ | ||
$this->assertSame('3.14159', $this->app['db']->escape(3.14159)); | ||
$this->assertSame('-3.14159', $this->app['db']->escape(-3.14159)); | ||
} | ||
|
||
public function testEscapeBool() | ||
{ | ||
$this->assertSame('1', $this->app['db']->escape(true)); | ||
$this->assertSame('0', $this->app['db']->escape(false)); | ||
} | ||
|
||
public function testEscapeNull() | ||
{ | ||
$this->assertSame('null', $this->app['db']->escape(null)); | ||
$this->assertSame('null', $this->app['db']->escape(null, true)); | ||
} | ||
|
||
public function testEscapeBinary() | ||
{ | ||
$this->assertSame("x'dead00beef'", $this->app['db']->escape(hex2bin('dead00beef'), true)); | ||
} | ||
|
||
public function testEscapeString() | ||
{ | ||
$this->assertSame("'2147483647'", $this->app['db']->escape('2147483647')); | ||
$this->assertSame("'true'", $this->app['db']->escape('true')); | ||
$this->assertSame("'false'", $this->app['db']->escape('false')); | ||
$this->assertSame("'null'", $this->app['db']->escape('null')); | ||
$this->assertSame("'Hello\'World'", $this->app['db']->escape("Hello'World")); | ||
} | ||
|
||
public function testEscapeStringInvalidUtf8() | ||
{ | ||
$this->expectException(RuntimeException::class); | ||
|
||
$this->app['db']->escape("I am hiding an invalid \x80 utf-8 continuation byte"); | ||
} | ||
|
||
public function testEscapeStringNullByte() | ||
{ | ||
$this->expectException(RuntimeException::class); | ||
|
||
$this->app['db']->escape("I am hiding a \00 byte"); | ||
} | ||
} |
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.