str_getcsv won't work correctly in some special cases
オープン
まだ誰も着手していません。
Bug
Extension: standard
Status: Needs Triage
- 主要言語
- C
- スター
- 40.4k
- フォーク
- 8.2k
- 平均マージ
- 2日 15時間
- マージ済み PR(30日)
- 103
説明
Description
The function should not rebuild the string-annotation in the CSV-String by using the commas, if str_getcsv is used in the first step of the small algorithm.
The following code is motivated by the example of durik at 3ilab dot net : He mentioned: "...
Why not use explode() instead of str_getcsv() to parse rows? Because explode() would not treat possible enclosured parts of string or escaped characters correctly."
<?php
$string =<<<DOMTEST
"PHP, Java","Python"
"PHP2, Java2","Python"
"PHP3, Java3","Python"
DOMTEST;
$data = str_getcsv($string, "\n" );
foreach ($data as &$row) {
$row = str_getcsv($row, ',');
}
var_dump($data);
Resulted in this output:
array(3) {
[0]=>
array(3) {
[0]=>
string(3) "PHP"
[1]=>
string(5) " Java"
[2]=>
string(6) "Python"
}
[1]=>
array(3) {
[0]=>
string(4) "PHP2"
[1]=>
string(6) " Java2"
[2]=>
string(6) "Python"
}
[2]=>
&array(3) {
[0]=>
string(4) "PHP3"
[1]=>
string(6) " Java3"
[2]=>
string(6) "Python"
}
}
But I expected this output instead:
array(3) {
[0]=>
array(2) {
[0]=>
string(8) "PHP, Java"
[1]=>
string(6) "Python"
}
[1]=>
array(2) {
[0]=>
string(10) "PHP2, Java2"
[1]=>
string(6) "Python"
}
[2]=>
&array(2) {
[0]=>
string(10) "PHP3, Java3"
[1]=>
string(6) "Python"
}
}
PHP Version
8.2.1
Operating System
No response
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
まず、改行およびカンマの区切り文字を使って str_getcsv で提供された PHP の例を再現し、次に、引用符で囲まれたカンマとエスケープされた文字に対する関数の既存の動作を調べます。Issue では実装ファイルもテストも指定されていません。意図した入れ子のパース動作が確立され、リグレッションテストでカバーされれば完了です。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- php
- 領域
- backend-api-design
- issue の種類
- バグ
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 35/100