fix PDO::quote api when input string contain a NUL ASCII character
This commit is contained in:
parent
75c03f05d3
commit
57a41d71e9
|
@ -1463,7 +1463,7 @@ int pdo_sqlsrv_dbh_quote( _Inout_ pdo_dbh_t* dbh, _In_reads_(unquoted_len) const
|
||||||
if ( encoding == SQLSRV_ENCODING_UTF8 ) {
|
if ( encoding == SQLSRV_ENCODING_UTF8 ) {
|
||||||
quotes_needed = 3;
|
quotes_needed = 3;
|
||||||
}
|
}
|
||||||
for ( size_t index = 0; index < unquoted_len && unquoted[ index ] != '\0'; ++index ) {
|
for ( size_t index = 0; index < unquoted_len; ++index ) {
|
||||||
if ( unquoted[ index ] == '\'' ) {
|
if ( unquoted[ index ] == '\'' ) {
|
||||||
++quotes_needed;
|
++quotes_needed;
|
||||||
}
|
}
|
||||||
|
@ -1480,7 +1480,7 @@ int pdo_sqlsrv_dbh_quote( _Inout_ pdo_dbh_t* dbh, _In_reads_(unquoted_len) const
|
||||||
// insert initial quote
|
// insert initial quote
|
||||||
( *quoted )[ out_current++ ] = '\'';
|
( *quoted )[ out_current++ ] = '\'';
|
||||||
|
|
||||||
for ( size_t index = 0; index < unquoted_len && unquoted[ index ] != '\0'; ++index ) {
|
for ( size_t index = 0; index < unquoted_len; ++index ) {
|
||||||
if ( unquoted[ index ] == '\'' ) {
|
if ( unquoted[ index ] == '\'' ) {
|
||||||
( *quoted )[ out_current++ ] = '\'';
|
( *quoted )[ out_current++ ] = '\'';
|
||||||
( *quoted )[ out_current++ ] = '\'';
|
( *quoted )[ out_current++ ] = '\'';
|
||||||
|
|
29
test/functional/pdo_sqlsrv/pdo_538_quote_nul.phpt
Normal file
29
test/functional/pdo_sqlsrv/pdo_538_quote_nul.phpt
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
--TEST--
|
||||||
|
Test the PDO::quote() method.
|
||||||
|
--SKIPIF--
|
||||||
|
<?php require('skipif.inc'); ?>
|
||||||
|
--FILE--
|
||||||
|
<?php
|
||||||
|
|
||||||
|
require_once 'MsCommon.inc';
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
$connection = connect();
|
||||||
|
//$connection->setAttribute( PDO::SQLSRV_ATTR_DIRECT_QUERY, PDO::SQLSRV_ENCODING_SYSTEM );
|
||||||
|
|
||||||
|
$str = "XX\0XX";
|
||||||
|
|
||||||
|
print("Original: " . str_replace("\0", "{NUL}", $str) . "\n");
|
||||||
|
$str = $connection->quote($str);
|
||||||
|
print("Quoted: " . str_replace("\0", "{NUL}", $str) . "\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
catch( PDOException $e ) {
|
||||||
|
die("Connection error: " . $e->getMessage());
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
|
||||||
|
--EXPECT--
|
||||||
|
Original: XX{NUL}XX
|
||||||
|
Quoted: 'XX{NUL}XX'
|
Loading…
Reference in a new issue