@@ -41,17 +41,69 @@ protected function setUp(): void {
4141 $ this ->connection = \OC ::$ server ->getDatabaseConnection ();
4242 }
4343
44- public function testConcat () {
44+ /**
45+ * @dataProvider providerTestConcatString
46+ */
47+ public function testConcatString ($ closure ) {
4548 $ query = $ this ->connection ->getQueryBuilder ();
49+ [$ real , $ arguments , $ return ] = $ closure ($ query );
50+ if ($ real ) {
51+ $ this ->addDummyData ();
52+ }
4653
47- $ query ->select ($ query ->func ()->concat ($ query -> createNamedParameter ( ' foo ' ), new Literal ( " 'bar' " ) ));
54+ $ query ->select ($ query ->func ()->concat (... $ arguments ));
4855 $ query ->from ('appconfig ' )
4956 ->setMaxResults (1 );
5057
5158 $ result = $ query ->execute ();
5259 $ column = $ result ->fetchOne ();
5360 $ result ->closeCursor ();
54- $ this ->assertEquals ('foobar ' , $ column );
61+ $ this ->assertEquals ($ return , $ column );
62+ }
63+
64+ public function providerTestConcatString (): array {
65+ return [
66+ '1 column: string literal possible sql injection ' =>
67+ [function ($ q ) {
68+ return [false , [$ q ->expr ()->literal ("' \\, " .chr (8 ).chr (13 ))], '\'\\, ' .chr (8 ).chr (13 )];
69+ }],
70+ '1 column: string param possible sql injection ' =>
71+ [function ($ q ) {
72+ return [false , [$ q ->createNamedParameter ("' \\, " .chr (8 ).chr (13 ))], '\'\\, ' .chr (8 ).chr (13 )];
73+ }],
74+ '1 column: string param unicode ' =>
75+ [function ($ q ) {
76+ return [false , [$ q ->createNamedParameter ('👍 ' )], '👍 ' ];
77+ }],
78+ '1 column: string parameter possible sql injection ' =>
79+ [function ($ q ) {
80+ return [false , [$ q ->createNamedParameter ("' \\, " .chr (8 ).chr (13 ))], '\'\\, ' .chr (8 ).chr (13 )];
81+ }],
82+ '2 columns: string param and string param ' =>
83+ [function ($ q ) {
84+ return [false , [$ q ->createNamedParameter ('foo ' ), $ q ->createNamedParameter ('bar ' )], 'foobar ' ];
85+ }],
86+ '2 columns: string param and int literal ' =>
87+ [function ($ q ) {
88+ return [false , [$ q ->createNamedParameter ('foo ' ), $ q ->expr ()->literal (1 )], 'foo1 ' ];
89+ }],
90+ '2 columns: string param and string literal ' =>
91+ [function ($ q ) {
92+ return [false , [$ q ->createNamedParameter ('foo ' ), $ q ->expr ()->literal ('bar ' )], 'foobar ' ];
93+ }],
94+ '2 columns: string real and int literal ' =>
95+ [function ($ q ) {
96+ return [true , ['configkey ' , $ q ->expr ()->literal (2 )], '12 ' ];
97+ }],
98+ '4 columns: string literal ' =>
99+ [function ($ q ) {
100+ return [false , [$ q ->expr ()->literal ('foo ' ), $ q ->expr ()->literal ('bar ' ), $ q ->expr ()->literal ('foo ' ), $ q ->expr ()->literal ('bar ' )], 'foobarfoobar ' ];
101+ }],
102+ '4 columns: int literal ' =>
103+ [function ($ q ) {
104+ return [false , [$ q ->expr ()->literal (1 ), $ q ->expr ()->literal (2 ), $ q ->expr ()->literal (3 ), $ q ->expr ()->literal (4 )], '1234 ' ];
105+ }],
106+ ];
55107 }
56108
57109 protected function clearDummyData (): void {
0 commit comments