http://www.mediawiki.org/wiki/Special:Code/MediaWiki/90051

Revision: 90051
Author:   yaron
Date:     2011-06-14 14:56:15 +0000 (Tue, 14 Jun 2011)
Log Message:
-----------
Fix to r86720 - previous regexp accidentally split on spaces, in addition to 
commas. Also added code to skip any empty lines at the top of 'CSV with header' 
files

Modified Paths:
--------------
    trunk/extensions/ExternalData/ED_Utils.php

Modified: trunk/extensions/ExternalData/ED_Utils.php
===================================================================
--- trunk/extensions/ExternalData/ED_Utils.php  2011-06-14 14:50:56 UTC (rev 
90050)
+++ trunk/extensions/ExternalData/ED_Utils.php  2011-06-14 14:56:15 UTC (rev 
90051)
@@ -70,11 +70,11 @@
                $arg = preg_replace ( "/\s\s+/", ' ', $arg ); // whitespace
 
                // Split text on commas, except for commas found within quotes
-               // and parentheses. Code copied from:
+               // and parentheses. Code based on:
                // 
http://stackoverflow.com/questions/1373735/regexp-split-string-by-commas-and-spaces-but-ignore-the-inside-quotes-and-parent#1381895
                $pattern = <<<END
         /
-       [,\s]++
+       [,]++
        (?=(?:(?:[^"]*+"){2})*+[^"]*+$)
        (?=(?:(?:[^']*+'){2})*+[^']*+$)
        (?=(?:[^()]*+\([^()]*+\))*+[^()]*+$)
@@ -319,11 +319,17 @@
                        }
                        fclose( $fp );
                //}
-               // now "flip" the data, turning it into a column-by-column
-               // array, instead of row-by-row
+               // Get header values, if this is 'csv with header'
                if ( $has_header ) {
                        $header_vals = array_shift( $table );
+                       // On the off chance that there are one or more blank
+                       // lines at the beginning, cycle through.
+                       while ( count( $header_vals ) == 0 ) {
+                               $header_vals = array_shift( $table );
+                       }
                }
+               // Now "flip" the data, turning it into a column-by-column
+               // array, instead of row-by-row.
                $values = array();
                foreach ( $table as $line ) {
                        foreach ( $line as $i => $row_val ) {


_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs

Reply via email to