From 2302eef5c93b722d5311549dd59d495ff11d3b0d Mon Sep 17 00:00:00 2001 From: Adam Baratz Date: Mon, 12 Sep 2016 17:32:50 -0400 Subject: [PATCH] Never quote values as raw binary data This reverts a1a18fca6e2a1690ea113dc2ebe0e7d22fdc71a0 which was intended to fix bug #52885. That commit introduced a BC break which wasn't universally desirable. The issue of quoting binary data (or NVARCHAR strings, or other nonstandard types) will have to be addressed separately. --- ext/pdo_dblib/dblib_driver.c | 48 ++++++------------------ ext/pdo_dblib/tests/pdo_dblib_quote.phpt | 2 + 2 files changed, 13 insertions(+), 37 deletions(-) diff --git a/ext/pdo_dblib/dblib_driver.c b/ext/pdo_dblib/dblib_driver.c index 23f59a6d9e7..64a3646b324 100644 --- a/ext/pdo_dblib/dblib_driver.c +++ b/ext/pdo_dblib/dblib_driver.c @@ -146,55 +146,29 @@ static zend_long dblib_handle_doer(pdo_dbh_t *dbh, const char *sql, size_t sql_l static int dblib_handle_quoter(pdo_dbh_t *dbh, const char *unquoted, size_t unquotedlen, char **quoted, size_t *quotedlen, enum pdo_param_type paramtype) { - int useBinaryEncoding = 0; - const char * hex = "0123456789abcdef"; size_t i; char * q; *quotedlen = 0; - /* - * Detect quoted length and if we should use binary encoding - */ + /* Detect quoted length, adding extra char for doubled single quotes */ for(i=0;i unquoted[i] || 127 < unquoted[i] ) { - useBinaryEncoding = 1; - break; - } if(unquoted[i] == '\'') ++*quotedlen; ++*quotedlen; } - if(useBinaryEncoding) { - /* - * Binary safe quoting - * Will implicitly convert for all data types except Text, DateTime & SmallDateTime - * - */ - *quotedlen = (unquotedlen * 2) + 2; /* 2 chars per byte +2 for "0x" prefix */ - q = *quoted = emalloc(*quotedlen+1); /* Add byte for terminal null */ + *quotedlen += 2; /* +2 for opening, closing quotes */ + q = *quoted = emalloc(*quotedlen+1); /* Add byte for terminal null */ + *q++ = '\''; - *q++ = '0'; - *q++ = 'x'; - for (i=0;i>4)&0xF]; - *q++ = hex[ (*unquoted++)&0xF]; + for (i=0;iquote(42, PDO::PARAM_INT)); var_dump($db->quote(null, PDO::PARAM_NULL)); var_dump($db->quote('\'', PDO::PARAM_STR)); var_dump($db->quote('foo', PDO::PARAM_STR)); +var_dump($db->quote('über', PDO::PARAM_STR)); ?> --EXPECT-- string(3) "'1'" @@ -22,3 +23,4 @@ string(4) "'42'" string(2) "''" string(4) "''''" string(5) "'foo'" +string(7) "'über'"