#38929 [NEW]: fputcsv() fgetcsv() inconsistency even number backslashes then enclosure char

Ask a Question related to PHP Bugs, Design and Development.

  1. #1

    Default #38929 [NEW]: fputcsv() fgetcsv() inconsistency even number backslashes then enclosure char

    From: mike at opendns dot com
    Operating system: Linux, debian sarge
    PHP version: 5.1.6
    PHP Bug Type: *Directory/Filesystem functions
    Bug description: fputcsv() fgetcsv() inconsistency even number backslashes then enclosure char

    Description:
    ------------
    If you write a string to file with fputcsv that contains an even number of
    backslashes follwed by the enclosure character, you don't get your
    enclosure character back when you read it back in with fgetcsv(). Then
    you'll get an extra trailing enclosure character at the end of your
    string.

    Reproduce code:
    ---------------
    $tmp_file = '/tmp/csv_f_up.tmp';

    $data_to_write = array('string contains even number of backslashes \\\\"
    followed by enclosure char');

    echo "data_to_write:\n";
    var_dump($data_to_write);

    $h_w = fopen($tmp_file, 'w');
    fputcsv($h_w, $data_to_write);
    fclose($h_w);

    $h_r = fopen($tmp_file, 'r');
    $data_read_in = fgetcsv($h_r);
    fclose($h_r);

    echo "data_read_in:\n";
    var_dump($data_read_in);

    Expected result:
    ----------------
    data_to_write:
    array(1) {
    [0]=>
    string(73) "string contains even number of backslashes \\" followed by
    enclosure char"
    }
    data_read_in:
    array(1) {
    [0]=>
    string(73) "string contains even number of backslashes \\" followed by
    enclosure char"
    }

    Actual result:
    --------------
    data_to_write:
    array(1) {
    [0]=>
    string(73) "string contains even number of backslashes \\" followed by
    enclosure char"
    }
    data_read_in:
    array(1) {
    [0]=>
    string(73) "string contains even number of backslashes \\ followed by
    enclosure char""
    }

    --
    Edit bug report at [url]http://bugs.php.net/?id=38929&edit=1[/url]
    --
    Try a CVS snapshot (PHP 4.4): [url]http://bugs.php.net/fix.php?id=38929&r=trysnapshot44[/url]
    Try a CVS snapshot (PHP 5.2): [url]http://bugs.php.net/fix.php?id=38929&r=trysnapshot52[/url]
    Try a CVS snapshot (PHP 6.0): [url]http://bugs.php.net/fix.php?id=38929&r=trysnapshot60[/url]
    Fixed in CVS: [url]http://bugs.php.net/fix.php?id=38929&r=fixedcvs[/url]
    Fixed in release: [url]http://bugs.php.net/fix.php?id=38929&r=alreadyfixed[/url]
    Need backtrace: [url]http://bugs.php.net/fix.php?id=38929&r=needtrace[/url]
    Need Reproduce Script: [url]http://bugs.php.net/fix.php?id=38929&r=needscript[/url]
    Try newer version: [url]http://bugs.php.net/fix.php?id=38929&r=oldversion[/url]
    Not developer issue: [url]http://bugs.php.net/fix.php?id=38929&r=support[/url]
    Expected behavior: [url]http://bugs.php.net/fix.php?id=38929&r=notwrong[/url]
    Not enough info: [url]http://bugs.php.net/fix.php?id=38929&r=notenoughinfo[/url]
    Submitted twice: [url]http://bugs.php.net/fix.php?id=38929&r=submittedtwice[/url]
    register_globals: [url]http://bugs.php.net/fix.php?id=38929&r=globals[/url]
    PHP 3 support discontinued: [url]http://bugs.php.net/fix.php?id=38929&r=php3[/url]
    Daylight Savings: [url]http://bugs.php.net/fix.php?id=38929&r=dst[/url]
    IIS Stability: [url]http://bugs.php.net/fix.php?id=38929&r=isapi[/url]
    Install GNU Sed: [url]http://bugs.php.net/fix.php?id=38929&r=gnused[/url]
    Floating point limitations: [url]http://bugs.php.net/fix.php?id=38929&r=float[/url]
    No Zend Extensions: [url]http://bugs.php.net/fix.php?id=38929&r=nozend[/url]
    MySQL Configuration Error: [url]http://bugs.php.net/fix.php?id=38929&r=mysqlcfg[/url]
    mike at opendns dot com Guest

  2. Similar Questions and Discussions

    1. #40501 [NEW]: fgetcsv can't handle trailing odd number of backslashes
      From: mike at opendns dot com Operating system: Linux, debian sarge PHP version: 5.2.1 PHP Bug Type: Filesystem function...
    2. #39538 [NEW]: fgetcsv can't handle starting newlines and trailing odd number of backslashes
      From: mike at opendns dot com Operating system: Linux, debian sarge PHP version: 5.2.0 PHP Bug Type: *Directory/Filesystem...
    3. #38918 [NEW]: fputcsv() fgetcsv() inconsistency odd number trailing backslashes
      From: mike at opendns dot com Operating system: Linux, debian sarge PHP version: 5.1.6 PHP Bug Type: Filesystem function...
    4. #25872 [Opn->Bgs]: Query of MS-Word char causes ISO number to show up instead of actual character
      ID: 25872 Updated by: iliaa@php.net Reported By: mrtima at aol dot com -Status: Open +Status: Bogus...
    5. #25872 [NEW]: Query of MS-Word char causes ISO number to show up instead of actual character
      From: mrtima at aol dot com Operating system: Any PHP version: 4.3.1 PHP Bug Type: MySQL related Bug description: Query of...
  3. #2

    Default #38929 [Opn->Bgs]: fputcsv() fgetcsv() inconsistency even number backslashes then enclosure char

    ID: 38929
    Updated by: [email]tony2001@php.net[/email]
    Reported By: mike at opendns dot com
    -Status: Open
    +Status: Bogus
    Bug Type: *Directory/Filesystem functions
    Operating System: Linux, debian sarge
    PHP Version: 5.1.6
    New Comment:

    The same problem as #38918.


    Previous Comments:
    ------------------------------------------------------------------------

    [2006-09-22 20:05:05] mike at opendns dot com

    Description:
    ------------
    If you write a string to file with fputcsv that contains an even number
    of backslashes follwed by the enclosure character, you don't get your
    enclosure character back when you read it back in with fgetcsv(). Then
    you'll get an extra trailing enclosure character at the end of your
    string.

    Reproduce code:
    ---------------
    $tmp_file = '/tmp/csv_f_up.tmp';

    $data_to_write = array('string contains even number of backslashes
    \\\\" followed by enclosure char');

    echo "data_to_write:\n";
    var_dump($data_to_write);

    $h_w = fopen($tmp_file, 'w');
    fputcsv($h_w, $data_to_write);
    fclose($h_w);

    $h_r = fopen($tmp_file, 'r');
    $data_read_in = fgetcsv($h_r);
    fclose($h_r);

    echo "data_read_in:\n";
    var_dump($data_read_in);

    Expected result:
    ----------------
    data_to_write:
    array(1) {
    [0]=>
    string(73) "string contains even number of backslashes \\" followed
    by enclosure char"
    }
    data_read_in:
    array(1) {
    [0]=>
    string(73) "string contains even number of backslashes \\" followed
    by enclosure char"
    }

    Actual result:
    --------------
    data_to_write:
    array(1) {
    [0]=>
    string(73) "string contains even number of backslashes \\" followed
    by enclosure char"
    }
    data_read_in:
    array(1) {
    [0]=>
    string(73) "string contains even number of backslashes \\ followed by
    enclosure char""
    }


    ------------------------------------------------------------------------


    --
    Edit this bug report at [url]http://bugs.php.net/?id=38929&edit=1[/url]
    tony2001@php.net Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139