php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #71588 str_getcsv partial string enclosure
Submitted: 2016-02-14 13:28 UTC Modified: 2016-02-15 00:39 UTC
From: JunkYardMail1 at Frontier dot com Assigned:
Status: Not a bug Package: Strings related
PHP Version: 5.6.18 OS: FreeBSD
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: JunkYardMail1 at Frontier dot com
New email:
PHP Version: OS:

 

 [2016-02-14 13:28 UTC] JunkYardMail1 at Frontier dot com
Description:
------------
---
From manual page: http://www.php.net/function.str-getcsv
---

If a string is partially in an enclosure then delimiter characters within the enclosed portion are not protected.


Test script:
---------------
$string = 'dhcp-class-identifier "Wireless Broadband R,outer", dhcp-client-identifier "", host-name "Wireless_Broadband_Router", domain-name "home"';

$options = str_getcsv($string, ',', '"', '\\');
foreach ($options as $option) {
	$send_options .= "\tsend " . trim($option) . ";\n";
}

echo $send_options;


Expected result:
----------------
send dhcp-class-identifier "Wireless Broadband R,outer";
send dhcp-client-identifier "";
send host-name "Wireless_Broadband_Router";
send domain-name "home";


Actual result:
--------------
send dhcp-class-identifier "Wireless Broadband R;
send outer";
send dhcp-client-identifier "";
send host-name "Wireless_Broadband_Router";
send domain-name "home";



Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2016-02-15 00:39 UTC] requinix@php.net
-Status: Open +Status: Not a bug
 [2016-02-15 00:39 UTC] requinix@php.net
That string doesn't follow the rules for CSV. Rules which vary by implementation, admittedly, but one common rule is that embedded quotes must be themselves quoted and the containing field as a whole must be quoted as well.

https://3v4l.org/c93T0

Which means CSV parsing is not suitable for your string. Regex is probably the way to go.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Apr 27 03:01:29 2024 UTC