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

Fix db escape negative integers #5277

Merged
merged 4 commits into from
Nov 20, 2021

Conversation

kenjis
Copy link
Member

@kenjis kenjis commented Nov 2, 2021

Description
Fixes #4973

Checklist:

  • Securely signed commits
  • Component(s) with PHPDoc blocks, only if necessary or adds value
  • Unit testing, with >80% coverage
  • User guide updated
  • Conforms to style guide

@@ -1201,7 +1203,7 @@ public function escape($str)
}

if (is_numeric($str) && $str < 0) {
Copy link
Member

Choose a reason for hiding this comment

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

Why is there a need to add this for negative numbers? I think we can remove this if block entirely as the last return will do the job.

Copy link
Member

@paulbalandan paulbalandan Nov 2, 2021

Choose a reason for hiding this comment

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

And it seems inconsistent, with negative numbers we get a string. For positive, we get numbers.

Copy link
Member Author

Choose a reason for hiding this comment

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

Good point!

For now, I remove it.

Copy link
Member Author

@kenjis kenjis Nov 2, 2021

Choose a reason for hiding this comment

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

However, I am not sure why this commit 19c173a fixed #606.

Copy link
Member

Choose a reason for hiding this comment

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

let's have @lonnieezell shed the light on this. 😂

Copy link
Member

Choose a reason for hiding this comment

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

I don't remember exactly. It's been 4 years :) . Looking back through the issue, though, I'm guessing that wrapping it in quotes would get it past the escaping and adding of the slash, which was then converted by MySQL into an INT or whatever type when it was saved to the table.

I would say as long as we have tests in place that ensure his problem is still fixed, and it doesn't escape the negative sign, this is fine.

Copy link
Member Author

Choose a reason for hiding this comment

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

@lonnieezell Thanks!

@kenjis kenjis force-pushed the fix-escape-negative-integers branch from e3571ae to b009bfd Compare November 2, 2021 10:56
@kenjis kenjis assigned lonnieezell and unassigned lonnieezell Nov 2, 2021
@kenjis kenjis requested a review from lonnieezell November 2, 2021 23:46
@kenjis kenjis added database Issues or pull requests that affect the database layer bug Verified issues on the current code behavior or pull requests that will fix them labels Nov 6, 2021
@@ -40,7 +40,7 @@ protected function setUp(): void
*/
public function testEscapeProtectsNegativeNumbers()
Copy link
Member

Choose a reason for hiding this comment

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

This should be renamed to say that this does not escape negative numbers now.

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed.

@kenjis kenjis force-pushed the fix-escape-negative-integers branch from b009bfd to 127b9cf Compare November 20, 2021 06:42
@kenjis kenjis requested a review from paulbalandan November 20, 2021 06:44
@kenjis kenjis merged commit 7aa7fcf into codeigniter4:develop Nov 20, 2021
@kenjis kenjis deleted the fix-escape-negative-integers branch November 20, 2021 10:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Verified issues on the current code behavior or pull requests that will fix them database Issues or pull requests that affect the database layer
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Bug: Query builder escapes negative integers
3 participants