php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #66588 SplFileObject::fgetcsv incorrectly returns a row on premature EOF
Submitted: 2014-01-27 16:15 UTC Modified: 2014-03-28 19:50 UTC
From: jameshfisher at gmail dot com Assigned:
Status: Verified Package: SPL related
PHP Version: 5.5.8 OS: Ubuntu 12.04.4 LTS
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: jameshfisher at gmail dot com
New email:
PHP Version: OS:

 

 [2014-01-27 16:15 UTC] jameshfisher at gmail dot com
Description:
------------
---
From manual page: http://www.php.net/splfileobject.fgetcsv
---



Test script:
---------------
Assume the file `invalid.csv` contains:

    blah,"blah

Then run the script below:

    #!/usr/bin/env php5
    <?php

    $s = new \SplFileObject('invalid.csv');

    $r = NULL;

    while (!$s->eof())
    {
      var_dump($s->fgetcsv(',','"'));
    }


Expected result:
----------------
An error, signalled by FALSE, as described in the documentation for the method:

    $ ./test.php 
    bool(false)


Actual result:
--------------
The cell in the file that does not have a closing quotation mark is treated as if EOF is the closing quotation mark. This is not compliant with the RFC: https://tools.ietf.org/html/rfc4180

    $ ./test.php 
    array(2) {
      [0]=>
      string(4) "blah"
      [1]=>
      string(5) "blah
    "
    }


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2014-03-28 19:50 UTC] levim@php.net
-Status: Open +Status: Verified
 
PHP Copyright © 2001-2017 The PHP Group
All rights reserved.
Last updated: Sun Nov 19 01:31:42 2017 UTC