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

bugfix: pg_escape_string() in serendipity_db_escape_string() works again #855

Open
wants to merge 8 commits into
base: master
Choose a base branch
from

Conversation

HQJaTu
Copy link
Contributor

@HQJaTu HQJaTu commented Oct 8, 2024

Docs: https://www.php.net/manual/en/function.pg-escape-string.php

In PHP 8.1+ there is no default connection. A mandatory connection must be given as a parameter. This PR restores PostgreSQL support for S9y.

Not sure if PHP <8.1 must be supported. If yes, PHP_MAJOR_VERSION and PHP_MINOR_VERSION could be checked to determine which interface of pg_escape_string() needs to be used.

@onli
Copy link
Member

onli commented Oct 13, 2024

Great :)

Not sure if PHP <8.1 must be supported. If yes, PHP_MAJOR_VERSION and PHP_MINOR_VERSION could be checked to determine which interface of pg_escape_string() needs to be used.

It would be nice to support older PHP versions. It makes upgrades for old blogs a lot easier, and so far we were still compatible I think.

@HQJaTu
Copy link
Contributor Author

HQJaTu commented Oct 13, 2024

Checked after the commit. Correction: PHP 8.1 is still supported by security updates.
https://www.php.net/supported-versions.php

My own agenda is to move into PHP 8.2. When stable status reached, then bump into 8.3 to see what breaks.

Comment on lines 97 to 99
if (PHP_MAJOR_VERSION < 8 || (PHP_MAJOR_VERSION == 8 && PHP_MINOR_VERSION < 1))
# Last supported version is PHP 8.0
return pg_escape_string($string);
Copy link
Member

@onli onli Oct 13, 2024

Choose a reason for hiding this comment

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

What do you think about this instead (untested)?

if (version_compare(PHP_VERSION, '8.1.0', '<')) {
    # Versions before 8.1 give the connection by default
    return pg_escape_string($string);
}

That's how the core would usually express that if, and I think it's a bit clearer, isn't it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants