1--TEST-- 2PDO PgSQL Bug #62479 (PDO-psql cannot connect if password contains spaces) 3--SKIPIF-- 4<?php 5if (!extension_loaded('pdo') || !extension_loaded('pdo_pgsql')) die('skip not loaded'); 6require __DIR__ . '/config.inc'; 7require __DIR__ . '/../../../ext/pdo/tests/pdo_test.inc'; 8PDOTest::skip(); 9 10$dsn = getenv('PDOTEST_DSN'); 11if (empty($dsn)) die('skip no dsn found in env'); 12 13$db = PDOTest::test_factory(__DIR__ . '/common.phpt'); 14$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); 15 16 17$user = 'pdo_test_'.rand(5, 400); 18$pass = 'testpass'; 19 20// Assume that if we can't create or drop a user, this test needs to be skipped 21try { 22 $db->exec("DROP USER IF EXISTS $user"); 23 $db->exec("CREATE USER $user WITH PASSWORD '$pass'"); 24} catch (PDOException $e) { 25 die("skip You need CREATEUSER permissions to run the test"); 26} 27 28// Peer authentication might prevent the test from properly running 29try { 30 $testConn = new PDO($dsn, $user, $pass); 31} catch (PDOException $e) { 32 echo "skip ".$e->getMessage(); 33} 34 35$db->exec("DROP USER $user"); 36 37?> 38--FILE-- 39<?php 40require __DIR__ . '/config.inc'; 41require __DIR__ . '/../../../ext/pdo/tests/pdo_test.inc'; 42$pdo = PDOTest::test_factory(__DIR__ . '/common.phpt'); 43$pdo->setAttribute(PDO::ATTR_EMULATE_PREPARES, true); 44$rand = rand(5, 400); 45$user = "pdo_test_$rand"; 46$template = "CREATE USER $user WITH PASSWORD '%s'"; 47$dropUser = "DROP USER $user"; 48$testQuery = 'SELECT 1 as verification'; 49 50// Create temp user with space in password 51$sql = sprintf($template, 'my password'); 52$pdo->query($sql); 53$testConn = new PDO($config['ENV']['PDOTEST_DSN'], $user, "my password"); 54$result = $testConn->query($testQuery)->fetch(); 55$check = $result[0]; 56var_dump($check); 57 58// Remove the user 59$pdo->query($dropUser); 60 61// Create a user with a space and single quote 62$sql = sprintf($template, "my pass''word"); 63$pdo->query($sql); 64 65$testConn = new PDO($config['ENV']['PDOTEST_DSN'], $user, "my pass'word"); 66$result = $testConn->query($testQuery)->fetch(); 67$check = $result[0]; 68var_dump($check); 69 70// Remove the user 71$pdo->query($dropUser); 72?> 73--EXPECT-- 74int(1) 75int(1) 76