Uploaded image for project: 'CiviCRM'
  1. CiviCRM
  2. CRM-10751

bin/cli.class.php Incorrectly Parses CSV Headers

    Details

    • Type: Bug
    • Status: Done/Fixed
    • Priority: Trivial
    • Resolution: Fixed/Completed
    • Affects Version/s: 4.2.0
    • Fix Version/s: 4.3.0
    • Component/s: Core CiviCRM
    • Labels:
      None

      Description

      Line 328 in cli.class.php

      It reads in the first line of the CSV file, and sort of expects it to return NULL in case it didn't find any occurrences of the separator (default ',') so it can set the delimiter to ';' and try again.

      The problem is that fgetcsv does not return NULL in case it didn't come across the delimiter, it just sees whatever it read until the EOL has been reached as an element it was able to parse. So fgetcsv's return value is effectively an array with 1 element.

      Here's a little fix, instead of checking whether $header is false we could check if it's only got 1 element. If it only has one element it wasn't able to parse anything (or it would've created more than 1 element in the array)

      //header
      $header = fgetcsv($handle, 0, $this->separator);
      if (count($header) == 1)

      { // In case fgetcsv couldn't parse the header and dumped the whole line in 1 array element. $this->separator = ";"; rewind($handle); $header = fgetcsv($handle, 0, $this->separator); }

      if (count($header) == 1)

      { // In case fgetcsv couldn't parse the header and dumped the whole line in 1 array element. die("Invalid file format for " . $this->_file . ". It must be a valid csv with separator ',' or ';'\n"); }

        Attachments

          Activity

            People

            • Assignee:
              colemanw Coleman Watts
              Reporter:
              jeroen Jeroen Bensch
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Time Tracking

                Estimated:
                Original Estimate - Not Specified
                Not Specified
                Remaining:
                Remaining Estimate - 0 minutes
                0m
                Logged:
                Time Spent - 20 minutes
                20m