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
12 changes: 11 additions & 1 deletion include/db/postgres.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,17 @@ function serendipity_db_reconnect() {
* @return string output string
*/
function serendipity_db_escape_string($string) {
return pg_escape_string($string);
global $serendipity;

if (is_null($string))
return $string;

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?


# From PHP 8.1 onwards
return pg_escape_string($serendipity['dbConn'], $string);
}

/**
Expand Down