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: BaseConnection::_escapeString() should accept Stringable #8739

Closed

Conversation

kenjis
Copy link
Member

@kenjis kenjis commented Apr 9, 2024

Description
It was accepted in 4.4 because of no strict types.
In 4.5, Stringable should be also accepted.

See also codeigniter4/shield#1092

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

@kenjis kenjis added the bug Verified issues on the current code behavior or pull requests that will fix them label Apr 9, 2024
Copy link
Contributor

@datamweb datamweb left a comment

Choose a reason for hiding this comment

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

Thanks, I took a practical test, everything seems to work fine.

@datamweb
Copy link
Contributor

datamweb commented Apr 9, 2024

@kenjis shield support 7.4+ but Stringable is php>8 , how about?

@kenjis
Copy link
Member Author

kenjis commented Apr 9, 2024

@datamweb No problem. If a user uses PHP 7.4, composer installs CI 4.4.

@kenjis kenjis added breaking change Pull requests that may break existing functionalities docs needed Pull requests needing documentation write-ups and/or revisions. labels Apr 9, 2024
@kenjis kenjis force-pushed the fix-BaseConnection-_escapeString branch from ad23ec6 to db17a77 Compare April 9, 2024 23:59
@kenjis kenjis force-pushed the fix-BaseConnection-_escapeString branch from db17a77 to 4825f89 Compare April 10, 2024 03:53
@kenjis kenjis removed the docs needed Pull requests needing documentation write-ups and/or revisions. label Apr 10, 2024
@kenjis
Copy link
Member Author

kenjis commented Apr 10, 2024

Added docs.

@@ -20,6 +20,10 @@ Mandatory File Changes
Breaking Changes
****************

- **QueryBuilder:** Due to a bug fix, the parameter type of ``BaseBuilder::_escapeString()``
has been changed from ``string`` to ``string|Stringable``. If you are extending
this method, update the method paramtere type.
Copy link
Member

Choose a reason for hiding this comment

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

Typo: paramtere - parameter

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks! Done.

@@ -182,7 +183,7 @@ protected function _close()
/**
* Platform-dependant string escape
*/
protected function _escapeString(string $str): string
protected function _escapeString(string|Stringable $str): string
{
return str_replace("'", "''", remove_invisible_characters($str, false));
Copy link
Member

Choose a reason for hiding this comment

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

Does remove_invisible_characters also allow Stringable?

@@ -253,7 +254,7 @@ public function escape($str)
/**
* Platform-dependant string escape
*/
protected function _escapeString(string $str): string
protected function _escapeString(string|Stringable $str): string
Copy link
Member

Choose a reason for hiding this comment

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

Same question for pg_escape_string.

I think we need to add a string cast to both function calls.

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks for the good insight!

@kenjis kenjis changed the title fix: BaseBuilder::_escapeString() should accept Stringable fix: BaseConnection::_escapeString() should accept Stringable Apr 10, 2024
@kenjis kenjis added the database Issues or pull requests that affect the database layer label Apr 10, 2024
@kenjis
Copy link
Member Author

kenjis commented Apr 10, 2024

Go to #8756

@kenjis kenjis closed this Apr 10, 2024
@kenjis kenjis deleted the fix-BaseConnection-_escapeString branch April 10, 2024 23:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking change Pull requests that may break existing functionalities 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.

None yet

5 participants