Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:100737 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 69569 invoked from network); 21 Sep 2017 17:33:25 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 21 Sep 2017 17:33:25 -0000 Authentication-Results: pb1.pair.com smtp.mail=andreas@dqxtech.net; spf=permerror; sender-id=unknown Authentication-Results: pb1.pair.com header.from=andreas@dqxtech.net; sender-id=unknown Received-SPF: error (pb1.pair.com: domain dqxtech.net from 209.85.215.43 cause and error) X-PHP-List-Original-Sender: andreas@dqxtech.net X-Host-Fingerprint: 209.85.215.43 mail-lf0-f43.google.com Received: from [209.85.215.43] ([209.85.215.43:53548] helo=mail-lf0-f43.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 2F/06-62331-3E7F3C95 for ; Thu, 21 Sep 2017 13:33:24 -0400 Received: by mail-lf0-f43.google.com with SMTP id k9so6433337lfe.10 for ; Thu, 21 Sep 2017 10:33:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=dqxtech-net.20150623.gappssmtp.com; s=20150623; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=/VpS2So6fyjusWzs9lfXY4e3I/wxvkD/P6iQbYxU7zs=; b=ZZ2PyzCKFTk1V3fEu7oQEA3yCY/WVnzBdY7B9PVp/HS9wtXRYDOJ9iwhpUS8d1sbc5 UX42cWjEVGSHDJAkdaM3H0aoxqIB6JNOkyJ7lpNHLZEmlYwHUj5lMLarPo4WbD+8fbND nErugtySNMF8OnCMll43VoY3l2Licc3dGUG2zusCDX5PYKv9wniCwi02Cq/hND0CKZC3 yonV2jOgOkttCQrJWtPBRsn11zWgRbKIlua+CVs2bXvljCefNwTstRGRLY88J2vyCJ3R lTPEdgvAf3hXcClXiRbc2k/G4JqM9TqouSOVtn1A/oq37V2VjbSRFASS1Ej0+uNM9QO9 CMLQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=/VpS2So6fyjusWzs9lfXY4e3I/wxvkD/P6iQbYxU7zs=; b=otCoHeqdnlef/uIxqMCyaIx/yKgH36xIPBeT6j7IRQ/Y4x7iMNgpsc92EnbhffRnEC RNtfzG086pXh66RbyOdd+vcvMRUvIqh8yzEAJn4rYt5YIcyVBM0Sivh5a5MwJv8QUKGY uxyzip8h2LMPxkGv3FEsM4d0FK6z7kplwZB1d056Yzo/de8hx0hLlI8xxZ0Nhq7KtCdJ wJha1Vb+qhZekA1ZyU4V5OPeoP117yjDedaBEZUle2gkTR7rHvSDSG/iPFDtwAD5FPdR EmQtiAPrmtNMdskGm7RqK0oWA8OXFRs/Ylr6oUZmaLnQ1XkY/TACVG/tjn57pjJhA2l8 EenQ== X-Gm-Message-State: AHPjjUjzLWHghlBHPmucLcZckGpacMcqow2r1lOluRq+HnBjf821g75d RZxAv2DgeoXPZif7OnlCRljOi0BA X-Received: by 10.46.83.87 with SMTP id t23mr1424184ljd.188.1506015200095; Thu, 21 Sep 2017 10:33:20 -0700 (PDT) Received: from mail-lf0-f51.google.com (mail-lf0-f51.google.com. [209.85.215.51]) by smtp.googlemail.com with ESMTPSA id 68sm395581ljr.47.2017.09.21.10.33.18 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 21 Sep 2017 10:33:19 -0700 (PDT) Received: by mail-lf0-f51.google.com with SMTP id b127so6455927lfe.9 for ; Thu, 21 Sep 2017 10:33:18 -0700 (PDT) X-Google-Smtp-Source: AOwi7QBqX6tMHg/nuC9xXkYrR1d4w7DM11YQIZN8SbxTfeclByVLCQPhY6gni8ZjECyoODcS297o2lX/h4GW8dEx5bY= X-Received: by 10.25.39.81 with SMTP id n78mr967115lfn.79.1506015198626; Thu, 21 Sep 2017 10:33:18 -0700 (PDT) MIME-Version: 1.0 Received: by 10.25.212.79 with HTTP; Thu, 21 Sep 2017 10:32:57 -0700 (PDT) In-Reply-To: <7cf5adb8-0738-259e-6d1e-f966722fdae2@gmx.de> References: <7cf5adb8-0738-259e-6d1e-f966722fdae2@gmx.de> Date: Thu, 21 Sep 2017 19:32:57 +0200 X-Gmail-Original-Message-ID: Message-ID: To: "Christoph M. Becker" Cc: PHP internals Content-Type: text/plain; charset="UTF-8" Subject: Re: [PHP-DEV] fputcsv() and $escape character From: andreas@dqxtech.net (Andreas Hennings) So empty string would enable the standard behavior RFC 7111 with no escape char. If so, I support this. I don't know if '' or true / false / null should be this "special value". It has to be something that was not legal before, and that people should use intentionally and not by accident. I guess '' is good enough for this, or not worse than other options. One question: Does this also require a change in fgetcsv()? So it can read csv without escape character? I remember that fgetcsv() does currently tolerate some broken CSV. It should continue to do so for BC reasons. For the record, here are some links: https://stackoverflow.com/questions/44427926/data-gets-garbled-when-writing-to-csv-with-fputcsv-fgetcsv/46342634#46342634 https://bugs.php.net/bug.php?id=74713&edit=2 On Thu, Sep 21, 2017 at 1:43 PM, Christoph M. Becker wrote: > Hi everybody! > > There are several bug reports regarding "broken" fputcsv() behavior in > our tracker, namely, because the $escape parameter causes unexpected > results. For instance: > > $row = ['a\\"', 'bbb']; > > $fp = fopen('php://memory', 'w+'); > fputcsv($fp, $row); > rewind($fp); > echo stream_get_contents($fp); > fclose($fp); > ?> > > outputs > > "a\"",bbb > > instead of the expected > > "a\""",bbb > > I don't think the current behavior is a bug, but rather the escape > character is an extension to the CSV "standard" (RFC 7111). One can > practically disable the escape character by passing any character that > is not contained in any of the strings in the array; "\0" is usually a > good choice, so changing line 5 in the script above to the following > gives the desired behavior: > > fputcsv($fp, $row, ',', '"', "\0"); > > Cf. vs. . > > It is, however, not possible to pass an empty string as $escape > argument, because fputcsv() bails out in this case raising > > Warning: fputcsv(): escape must be a character > > I suggest to allow an empty string instead, and to consider making this > the default in a future version, probably after some time of deprecating > any other $escape argument. > > Thoughts? > > -- > Christoph M. Becker > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php >