xref: /PHP-8.1/ext/pdo/tests/bug_71447.phpt (revision 74859783)
1--TEST--
2PDO Common: Bug #71447 (Quotes inside comments not properly handled)
3--EXTENSIONS--
4pdo
5--SKIPIF--
6<?php
7$dir = getenv('REDIR_TEST_DIR');
8if (false == $dir) die('skip no driver');
9require_once $dir . 'pdo_test.inc';
10PDOTest::skip();
11?>
12--FILE--
13<?php
14if (getenv('REDIR_TEST_DIR') === false) putenv('REDIR_TEST_DIR='.__DIR__ . '/../../pdo/tests/');
15require_once getenv('REDIR_TEST_DIR') . 'pdo_test.inc';
16
17$db = PDOTest::factory();
18$db->setAttribute (\PDO::ATTR_ERRMODE, \PDO::ERRMODE_WARNING);
19$db->setAttribute (\PDO::ATTR_DEFAULT_FETCH_MODE, \PDO::FETCH_NUM);
20$db->setAttribute (\PDO::ATTR_EMULATE_PREPARES, false);
21$db->exec('CREATE TABLE test(id int)');
22$db->exec('INSERT INTO test VALUES(1)');
23
24// Comment without quotes or placeholders
25$stmt = $db->prepare("
26    SELECT -- That's all folks!
27        '\"abc\":8000'
28    FROM test
29");
30
31$stmt->execute();
32var_dump($stmt->fetchColumn());
33
34// Comment and placeholder within a string
35$stmt = $db->prepare("
36    SELECT
37        '\"abc\":8001 -- Wat?'
38    FROM test
39");
40
41$stmt->execute();
42var_dump($stmt->fetchColumn());
43
44// Comment with single quote
45$stmt = $db->prepare("
46    SELECT -- That's all folks!
47        '\"abc\":8002'
48    FROM test
49");
50
51$stmt->execute();
52var_dump($stmt->fetchColumn());
53
54// C-Style comment with single quote
55$stmt = $db->prepare("
56    SELECT /* That's all folks! */
57        '\"abc\":8003'
58    FROM test
59");
60
61$stmt->execute();
62var_dump($stmt->fetchColumn());
63
64// Comment with double quote
65$stmt = $db->prepare("
66    SELECT -- Is it only \"single quotes?
67        '\"abc\":8004'
68    FROM test
69");
70
71$stmt->execute();
72var_dump($stmt->fetchColumn());
73
74// Comment with ? placeholder
75$stmt = $db->prepare("
76    SELECT -- What about question marks here?
77        *
78    FROM test
79    WHERE id = ?
80");
81
82$stmt->execute([1]);
83var_dump($stmt->fetchColumn());
84
85// Comment with named placeholder
86$stmt = $db->prepare("
87    SELECT -- What about placeholders :bar
88        *
89    FROM test
90    WHERE id = :id
91");
92
93$stmt->execute(['id' => 1]);
94var_dump($stmt->fetchColumn());
95
96
97?>
98--EXPECT--
99string(10) ""abc":8000"
100string(18) ""abc":8001 -- Wat?"
101string(10) ""abc":8002"
102string(10) ""abc":8003"
103string(10) ""abc":8004"
104string(1) "1"
105string(1) "1"
106