svn: /pear/packages/File/trunk/ File/CSV.php tests/CSV/bug18049.csv tests/CSV/bug18049.phpt tests/CSV/bug18111.csv tests/CSV/bug18111.phpt

From: Date: Thu, 10 Mar 2011 20:13:19 +0000
Subject: svn: /pear/packages/File/trunk/ File/CSV.php tests/CSV/bug18049.csv tests/CSV/bug18049.phpt tests/CSV/bug18111.csv tests/CSV/bug18111.phpt
Groups: php.pear.cvs 
Request: Send a blank email to pear-cvs+get-61385@lists.php.net to get a copy of this message
dufuz Thu, 10 Mar 2011 20:13:19 +0000 Revision: http://svn.php.net/viewvc?view=revision&revision=309088 Log: Fixed Bug #18111: discoverFormat: Quote not detected in short lines [dufuz] Fixed Bug #18049: discoverFormat bug, Find all seps that are within qoutes [dufuz] Bugs: http://pear.php.net/bugs/18111 (unknown) http://pear.php.net/bugs/18049 (unknown) Changed paths: U pear/packages/File/trunk/File/CSV.php A pear/packages/File/trunk/tests/CSV/bug18049.csv A pear/packages/File/trunk/tests/CSV/bug18049.phpt A pear/packages/File/trunk/tests/CSV/bug18111.csv A pear/packages/File/trunk/tests/CSV/bug18111.phpt Modified: pear/packages/File/trunk/File/CSV.php =================================================================== --- pear/packages/File/trunk/File/CSV.php 2011-03-10 19:46:51 UTC (rev 309087) +++ pear/packages/File/trunk/File/CSV.php 2011-03-10 20:13:19 UTC (rev 309088) @@ -649,7 +649,7 @@ foreach ($lines as $line) { $orgLine = $line; foreach ($seps as $sep) { - $line = preg_replace("|^[^$quotes$sep]*$sep*([$quotes][^$quotes]*[$quotes])|sm", '_', $orgLine); + $line = preg_replace("|^[$quotes$sep]*$sep*([$quotes][^$quotes]*[$quotes])|sm", '_', $orgLine); // Find all seps that are within qoutes ///FIXME ... counts legitimit lines as bad ones @@ -702,7 +702,7 @@ $string = implode('', $lines); foreach (array('"', '\'') as $q) { - if (preg_match_all("|$sep(?:\s*?)(\=?[$q]).*([$q])$sep|Us", $string, $match)) { + if (preg_match_all("|$sep(?:\s*?)(\=?[$q]).*([$q])$sep?|Us", $string, $match)) { if ($match[1][0] == $match[2][0]) { $quote = $match[1][0]; break; Added: pear/packages/File/trunk/tests/CSV/bug18049.csv =================================================================== --- pear/packages/File/trunk/tests/CSV/bug18049.csv (rev 0) +++ pear/packages/File/trunk/tests/CSV/bug18049.csv 2011-03-10 20:13:19 UTC (rev 309088) @@ -0,0 +1,4 @@ +1001;"Dorpstraat 160" +1002;"Access Wiseguy (vakantie informatie punt)" +1004;"Gehandicapten sticht. Arnhem" +1090;"HWL algemeen" \ No newline at end of file Added: pear/packages/File/trunk/tests/CSV/bug18049.phpt =================================================================== --- pear/packages/File/trunk/tests/CSV/bug18049.phpt (rev 0) +++ pear/packages/File/trunk/tests/CSV/bug18049.phpt 2011-03-10 20:13:19 UTC (rev 309088) @@ -0,0 +1,27 @@ +--TEST-- +File_CSV Test Case bug18049: discoverFormat bug, Find all seps that are within qoutes +--FILE-- +<?php +// $Id: $ +/** + * Test for: + * - File_CSV::discoverFormat() + */ + +require_once 'File/CSV.php'; + +$file = dirname(__FILE__) . '/bug18049.csv'; +$conf = File_CSV::discoverFormat($file); +echo "Discovered fields: $conf[fields]\n"; +echo "Format:\n"; +print_r($conf); +?> +--EXPECT-- +Discovered fields: 2 +Format: +Array +( + [fields] => 2 + [sep] => ; + [quote] => " +) \ No newline at end of file Added: pear/packages/File/trunk/tests/CSV/bug18111.csv =================================================================== --- pear/packages/File/trunk/tests/CSV/bug18111.csv (rev 0) +++ pear/packages/File/trunk/tests/CSV/bug18111.csv 2011-03-10 20:13:19 UTC (rev 309088) @@ -0,0 +1,4 @@ +123456789;"1 test" +287654321;"3 too" +323456789;"3 test" +487654321;"4 too" \ No newline at end of file Added: pear/packages/File/trunk/tests/CSV/bug18111.phpt =================================================================== --- pear/packages/File/trunk/tests/CSV/bug18111.phpt (rev 0) +++ pear/packages/File/trunk/tests/CSV/bug18111.phpt 2011-03-10 20:13:19 UTC (rev 309088) @@ -0,0 +1,27 @@ +--TEST-- +File_CSV Test Case bug18111: discoverFormat: Quote not detected in short lines +--FILE-- +<?php +// $Id: $ +/** + * Test for: + * - File_CSV::discoverFormat() + */ + +require_once 'File/CSV.php'; + +$file = dirname(__FILE__) . '/bug18111.csv'; +$conf = File_CSV::discoverFormat($file); +echo "Discovered fields: $conf[fields]\n"; +echo "Format:\n"; +print_r($conf); +?> +--EXPECT-- +Discovered fields: 2 +Format: +Array +( + [fields] => 2 + [sep] => ; + [quote] => " +) \ No newline at end of file

« previous php.pear.cvs (#61385) next »