Skip to content

Commit

Permalink
fix: Connection::escapeString should escape backslashes (#197)
Browse files Browse the repository at this point in the history
* fix: Connection::escapeString should escape backslashes

* update changelog

* fix
  • Loading branch information
taka-oyama authored Mar 11, 2024
1 parent 13a9943 commit a4870d9
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 2 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ Changed
- Performance enhancements for `DB::pretend` statements, no longer incurring the overhead of creating transactions (#191)
- Set the `$defaultMorphKeyType` in `Schema\Builder` to `uuid` (#192)

Fixed
- `Connection::escapeString` now properly escapes backslashes (#197)

# v7.0.0 (2024-02-21)

Added
Expand Down
4 changes: 2 additions & 2 deletions src/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -482,8 +482,8 @@ protected function escapeBool($value)
protected function escapeString($value)
{
return str_contains($value, "\n")
? 'r"""' . addcslashes($value, '"') . '"""'
: '"' . addcslashes($value, '"') . '"';
? 'r"""' . addcslashes($value, '"\\') . '"""'
: '"' . addcslashes($value, '"\\') . '"';
}

/**
Expand Down
1 change: 1 addition & 0 deletions tests/ConnectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -537,6 +537,7 @@ public function test_escape(): void
$this->assertSame('-1', $conn->escape(-1));
$this->assertSame('1.1', $conn->escape(1.1));
$this->assertSame('"a"', $conn->escape('a'));
$this->assertSame('"\"a\\\\\\""', $conn->escape('"a\\"'));
$this->assertSame('r"""' . "\n" . '"""', $conn->escape("\n"));
$this->assertSame('[]', $conn->escape([]));
$this->assertSame('["a"]', $conn->escape(['a']));
Expand Down

0 comments on commit a4870d9

Please sign in to comment.