Issues (4)

Security Analysis    no request data  

This project does not seem to handle request data directly as such no vulnerable execution paths were found.

  Cross-Site Scripting
Cross-Site Scripting enables an attacker to inject code into the response of a web-request that is viewed by other users. It can for example be used to bypass access controls, or even to take over other users' accounts.
  File Exposure
File Exposure allows an attacker to gain access to local files that he should not be able to access. These files can for example include database credentials, or other configuration files.
  File Manipulation
File Manipulation enables an attacker to write custom data to files. This potentially leads to injection of arbitrary code on the server.
  Object Injection
Object Injection enables an attacker to inject an object into PHP code, and can lead to arbitrary code execution, file exposure, or file manipulation attacks.
  Code Injection
Code Injection enables an attacker to execute arbitrary code on the server.
  Response Splitting
Response Splitting can be used to send arbitrary responses.
  File Inclusion
File Inclusion enables an attacker to inject custom files into PHP's file loading mechanism, either explicitly passed to include, or for example via PHP's auto-loading mechanism.
  Command Injection
Command Injection enables an attacker to inject a shell command that is execute with the privileges of the web-server. This can be used to expose sensitive data, or gain access of your server.
  SQL Injection
SQL Injection enables an attacker to execute arbitrary SQL code on your database server gaining access to user data, or manipulating user data.
  XPath Injection
XPath Injection enables an attacker to modify the parts of XML document that are read. If that XML document is for example used for authentication, this can lead to further vulnerabilities similar to SQL Injection.
  LDAP Injection
LDAP Injection enables an attacker to inject LDAP statements potentially granting permission to run unauthorized queries, or modify content inside the LDAP tree.
  Header Injection
  Other Vulnerability
This category comprises other attack vectors such as manipulating the PHP runtime, loading custom extensions, freezing the runtime, or similar.
  Regex Injection
Regex Injection enables an attacker to execute arbitrary code in your PHP process.
  XML Injection
XML Injection enables an attacker to read files on your local filesystem including configuration files, or can be abused to freeze your web-server process.
  Variable Injection
Variable Injection enables an attacker to overwrite program variables with custom data, and can lead to further vulnerabilities.
Unfortunately, the security analysis is currently not available for your project. If you are a non-commercial open-source project, please contact support to gain access.

tests/integration/ParserTest.php (1 issue)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
/**
3
 * This file is part of graze/csv-token
4
 *
5
 * Copyright (c) 2016 Nature Delivered Ltd. <https://www.graze.com>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 *
10
 * @license https://github.com/graze/csv-token/blob/master/LICENSE.md
11
 * @link    https://github.com/graze/csv-token
12
 */
13
14
namespace Graze\CsvToken\Test\Integration;
15
16
use Graze\CsvToken\Csv\CsvConfiguration;
17
use Graze\CsvToken\Csv\CsvConfigurationInterface;
18
use Graze\CsvToken\Parser;
19
use Graze\CsvToken\Test\TestCase;
20
use Graze\CsvToken\Tokeniser\StringTokeniser;
21
use Graze\CsvToken\ValueParser\BoolValueParser;
22
use Graze\CsvToken\ValueParser\NumberValueParser;
23
use RuntimeException;
24
25
class ParserTest extends TestCase
26
{
27
    /**
28
     * @dataProvider parseData
29
     *
30
     * @param CsvConfigurationInterface $config
31
     * @param string                    $csv
32
     * @param array                     $valueParsers
33
     * @param array                     $expected
34
     */
35
    public function testParse(CsvConfigurationInterface $config, $csv, array $valueParsers, array $expected)
36
    {
37
        $tokeniser = new StringTokeniser($config, $csv);
38
        $parser = new Parser($valueParsers);
39
40
        $results = iterator_to_array($parser->parse($tokeniser->getTokens()));
41
42
        static::assertEquals($expected, $results);
43
    }
44
45
    /**
46
     * @return array
47
     */
48
    public function parseData()
49
    {
50
        return [
51
            [
52
                new CsvConfiguration(),
53
                '"some",\\N,"new' . "\n" . 'line",with\\' . "\n" . 'escaped,"in\\' . "\n" . 'quotes","\\\\"',
54
                [],
55
                [
56
                    ['some', null, "new\nline", "with\nescaped", "in\nquotes", '\\'],
57
                ],
58
            ],
59
            [
60
                new CsvConfiguration([
61
                    CsvConfiguration::OPTION_DOUBLE_QUOTE => true,
62
                ]),
63
                '"end""","""start","""both""","",""""',
64
                [],
65
                [['end"', '"start', '"both"', '', '"']],
66
            ],
67
            [
68
                new CsvConfiguration([
69
                    CsvConfiguration::OPTION_DELIMITER    => '|',
70
                    CsvConfiguration::OPTION_QUOTE        => "'",
71
                    CsvConfiguration::OPTION_ESCAPE       => '\\',
72
                    CsvConfiguration::OPTION_DOUBLE_QUOTE => true,
73
                    CsvConfiguration::OPTION_NEW_LINES    => ['---'],
74
                    CsvConfiguration::OPTION_NULL         => '\\N',
75
                ]),
76
                "'some'|text|'\\'here'|\\N|'with''quotes'---'another'|'line'",
77
                [],
78
                [
79
                    ['some', 'text', "'here", null, "with'quotes"],
80
                    ['another', 'line'],
81
                ],
82
            ],
83
            [
84
                new CsvConfiguration([
85
                    CsvConfiguration::OPTION_NULL => 'null',
86
                ]),
87
                '"text",1.2,false,true,12,2.3e-34,-2341,null,pants',
88
                [
89
                    new BoolValueParser(),
90
                    new NumberValueParser(),
91
                ],
92
                [
93
                    ['text', 1.2, false, true, 12, 2.3e-34, -2341, null, 'pants'],
94
                ],
95
            ],
96
            [
97
                new CsvConfiguration(),
98
                '',
99
                [],
100
                [],
101
            ],
102
            [
103
                new CsvConfiguration(),
104
                'text\\Nthing,\\Nstart,end\\N,\\N,"\\N"',
105
                [],
106
                [
107
                    ['text\\Nthing', '\\Nstart', 'end\\N', null, 'N'],
108
                ],
109
            ],
110
            [
111
                new CsvConfiguration(),
112
                "한국말\n조선말,한국말",
113
                [],
114
                [
115
                    ['한국말'],
116
                    ['조선말', '한국말'],
117
                ],
118
            ],
119
            [
120
                new CsvConfiguration(),
121
                '"1","2","3"' . "\n",
122
                [],
123
                [
124
                    ['1', '2', '3'],
125
                ],
126
            ],
127
            [ // no quote and double quote should do nothing
128
                new CsvConfiguration([
129
                    CsvConfiguration::OPTION_QUOTE        => '',
130
                    CsvConfiguration::OPTION_DOUBLE_QUOTE => true,
131
                ]),
132
                'text,things"here,and\,here',
133
                [],
134
                [
135
                    ['text', 'things"here', 'and,here'],
136
                ],
137
            ],
138
            [
139
                new CsvConfiguration([
140
                    CsvConfiguration::OPTION_ESCAPE => '',
141
                ]),
142
                '"text","here","and\,here"',
143
                [],
144
                [
145
                    ['text', 'here', 'and\,here'],
146
                ],
147
            ],
148
            [
149
                new CsvConfiguration([
150
                    CsvConfiguration::OPTION_DELIMITER    => '|',
151
                    CsvConfiguration::OPTION_ESCAPE       => '~',
152
                    CsvConfiguration::OPTION_QUOTE        => '`',
153
                    CsvConfiguration::OPTION_NULL         => 'null',
154
                    CsvConfiguration::OPTION_DOUBLE_QUOTE => true,
155
                ]),
156
                '`string`|`other,thing`|some stuff|escaped ~\\n|``` all the `` quotes `|null',
157
                [],
158
                [['string', 'other,thing', 'some stuff', 'escaped \n', '` all the ` quotes ', null]],
159
            ],
160
        ];
161
    }
162
163
    /**
164
     * @dataProvider parseExceptionsData
165
     *
166
     * @param string $csv
167
     * @param string $exception
168
     */
169
    public function testParseExceptions($csv, $exception)
170
    {
171
        $tokeniser = new StringTokeniser(new CsvConfiguration(), $csv);
172
        $parser = new Parser();
173
174
        static::expectException($exception);
175
176
        iterator_to_array($parser->parse($tokeniser->getTokens()));
177
    }
178
179
    /**
180
     * @return array
181
     */
182
    public function parseExceptionsData()
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
183
    {
184
        return [
185
            ['"string"stuff,things', RuntimeException::class], // extra text after a closing quote
186
            ['"string', RuntimeException::class], // no closing quote
187
        ];
188
    }
189
}
190