Package home | Report new bug | New search | Development Roadmap Status: Open | Feedback | All | Closed Since Version 2.0.0

Bug #9137 _hasUnclosedQuotes() doesn't properly handle a double slash before an end quote
Submitted: 2006-10-23 06:19 UTC
From: me at calebbrown dot id dot au Assigned: chagenbu
Status: Closed Package: Mail (version 1.1.14)
PHP Version: 4.3.11 OS: Linux
Roadmaps: (Not assigned)    
Subscription  


 [2006-10-23 06:19 UTC] me at calebbrown dot id dot au (Caleb Brown)
Description: ------------ When an email address such as '"John Doe\\" <text@example.com>' is passed to RFC822 to be validated _hasUnclosedQuotes() is detecting the '\"' at the end of the string and presumes that the quote has been escaped. Because it only finds a single opening quote it presumes that the string has unclosed quotes and thinks that the email address is invalid. Test script: --------------- <?php require_once("Mail/RFC822.php"); require_once("PEAR.php"); $addresses = array( array('name' => 'John Doe', 'email' => 'test@example.com'), array('name' => 'John Doe\\', 'email' => 'test@example.com') ); for($i = 0; $i < count($addresses); $i++) { // construct the address $address = "\"".addslashes($addresses[$i]['name'])."\" ". "<".$addresses[$i]['email'].">"; $parsedAddresses = Mail_RFC822::parseAddressList($address); if(PEAR::isError($parsedAddresses)) { echo $address." :: Failed to validate\n"; } else { echo $address." :: Parsed\n"; } } ?> Expected result: ---------------- "John Doe" <test@example.com> :: Parsed "John Doe\\" <test@example.com> :: Parsed Actual result: -------------- "John Doe" <test@example.com> :: Parsed "John Doe\\" <test@example.com> :: Failed to validate

Comments

 [2007-07-08 04:20 UTC] chagenbu (Chuck Hagenbuch)
I've committed a test for this to make sure it stays on the radar.
 [2008-04-06 07:35 UTC] doconnor (Daniel O'Connor)
I think this is a slightly better test case: <?php require_once "Mail/RFC822.php"; require_once "PEAR.php" ; $addresses = array( array('raw' => '"John Doe" <test@example.com>'), array('raw' => '"John Doe' . chr(92) . '" <test@example.com>'), array('raw' => '"John Doe' . chr(92) . chr(92) . '" <test@example.com>'), array('raw' => '"John Doe' . chr(92) . chr(92) . chr(92) . '" <test@example.com>'), array('raw' => '"John Doe' . chr(92) . chr(92) . chr(92) . chr(92) . '" <test@example.com>'), array('raw' => '"John Doe <test@example.com>'), ); for($i = 0; $i < count($addresses); $i++) { // construct the address $address = $addresses[$i]['raw']; $parsedAddresses = Mail_RFC822::parseAddressList($address); if(PEAR::isError($parsedAddresses)) { echo $address." :: Failed to validate\n"; } else { echo $address." :: Parsed\n"; } } Expect: ---------- php ---------- "John Doe" <test@example.com> :: Parsed "John Doe\" <test@example.com> :: Failed to validate "John Doe\\" <test@example.com> :: Parsed "John Doe\\\" <test@example.com> :: Failed to validate "John Doe\\\\" <test@example.com> :: Parsed "John Doe <test@example.com> :: Failed to validate
 [2008-06-04 00:31 UTC] slusarz (Michael Slusarz)
Added a patch that should fix this problem, and fixes the problem where the previous code was counting escaped quotes inside of quoted string. RFC 822 does not require that quotes be closed inside the string, so these quotes need to be ignored.
 [2008-06-06 04:50 UTC] chagenbu (Chuck Hagenbuch)
This bug has been fixed in CVS. If this was a documentation problem, the fix will appear on pear.php.net by the end of next Sunday (CET). If this was a problem with the pear.php.net website, the change should be live shortly. Otherwise, the fix will appear in the package's next release. Thank you for the report and for helping us make PEAR better. Committed the new test and the patch, thanks. Michael, after this sits enough for comfort, ping me and we'll make sure to get a new release out. Thanks!