AW: [PEAR-DEV] [Patch] Use str_replace instead of preg_replace inNet_SMTP/SMTP.php
| From: | Matthias Pigulla | Date: | Sun, 19 Sep 2004 20:37:22 +0000 |
| Subject: | AW: [PEAR-DEV] [Patch] Use str_replace instead of preg_replace inNet_SMTP/SMTP.php | ||
| Groups: | php.pear.dev | ||
| Request: | Send a blank email to pear-dev+get-33457@lists.php.net to get a copy of this message | ||
Correctness of this replacement is nothing you could show with a test case, as long as you
don't test every possible input ;).
However, I'll be glad to contribute a test that checks for the (as far as I can see)
"critical" constellations. Attached you'll find quotedata.phpt(.txt). I've never
written a phpt unit test before, I hope it works correctly. As I said, the old code did not handle
leading newlines correctly and thus does not pass the test.
Besides that, I just noticed the inline doc says "change Mac (\r) linefeeds...". Neither
the old code nor the patch do perform \r => \r\n replacements! Bug or wrong documentation?
Best regards,
Matthias
> -----Ursprüngliche Nachricht-----
> Von: Jon Parise [mailto:jon@php.net]
> Gesendet: Sonntag, 19. September 2004 19:27
> An: pear-dev@lists.php.net
> Cc: Chuck Hagenbuch
> Betreff: Re: [PEAR-DEV] [Patch] Use str_replace instead of
> preg_replace inNet_SMTP/SMTP.php
>
> I think that makes ense to me, although I'm pretty short on
> time at the moment, too.
>
> If you can submit a unit test (for the tests/ directory) that
> passes under both the old and new code, I'll be happy to
> apply the change.
--TEST-- Net_SMTP: Correct quotedata() \n => \r\n replacement --FILE-- <?php require_once 'SMTP.php'; $test = array( "\n" => "\r\n", "\r\n" => "\r\n", "\nxx" => "\r\nxx", "xx\n" => "xx\r\n", "xx\nxx" => "xx\r\nxx", "\n\nxx" => "\r\n\r\nxx", "xx\n\nxx" => "xx\r\n\r\nxx", "xx\n\n" => "xx\r\n\r\n", "\r\nxx" => "\r\nxx", "xx\r\n" => "xx\r\n", "xx\r\nxx" => "xx\r\nxx", "\r\n\r\nxx" => "\r\n\r\nxx", "xx\r\n\r\nxx" => "xx\r\n\r\nxx", "xx\r\n\r\n" => "xx\r\n\r\n", "\r\n\nxx" => "\r\n\r\nxx", "\n\r\nxx" => "\r\n\r\nxx", "xx\r\n\nxx" => "xx\r\n\r\nxx", "xx\n\r\nxx" => "xx\r\n\r\nxx", "xx\r\n\n" => "xx\r\n\r\n", "xx\n\r\n" => "xx\r\n\r\n", /* Test for \r => \r\n replacement? Uncomment this: "\r" => "\r\n", "\rxx" => "\r\nxx", "xx\rxx" => "xx\r\nxx", "xx\r" => "xx\r\n" */ ); function prettyprint($x) { return str_replace(array("\r", "\n"), array('\r', '\n'), $x); } $hadError = false; foreach($test as $input => $expect) { $output = $input; Net_SMTP::quotedata($output); if ($output != $expect) { print "Error: input ".prettyprint($input).", output ".prettyprint($output).", expected ".prettyprint($expect)."\n"; $hadError = true; } } if (!$hadError) print 'Success!'; --EXPECT-- Success!
--TEST-- Net_SMTP: Correct quotedata() \n => \r\n replacement --FILE-- <?php require_once 'SMTP.php'; $test = array( "\n" => "\r\n", "\r\n" => "\r\n", "\nxx" => "\r\nxx", "xx\n" => "xx\r\n", "xx\nxx" => "xx\r\nxx", "\n\nxx" => "\r\n\r\nxx", "xx\n\nxx" => "xx\r\n\r\nxx", "xx\n\n" => "xx\r\n\r\n", "\r\nxx" => "\r\nxx", "xx\r\n" => "xx\r\n", "xx\r\nxx" => "xx\r\nxx", "\r\n\r\nxx" => "\r\n\r\nxx", "xx\r\n\r\nxx" => "xx\r\n\r\nxx", "xx\r\n\r\n" => "xx\r\n\r\n", "\r\n\nxx" => "\r\n\r\nxx", "\n\r\nxx" => "\r\n\r\nxx", "xx\r\n\nxx" => "xx\r\n\r\nxx", "xx\n\r\nxx" => "xx\r\n\r\nxx", "xx\r\n\n" => "xx\r\n\r\n", "xx\n\r\n" => "xx\r\n\r\n", /* Test for \r => \r\n replacement? Uncomment this: "\r" => "\r\n", "\rxx" => "\r\nxx", "xx\rxx" => "xx\r\nxx", "xx\r" => "xx\r\n" */ ); function prettyprint($x) { return str_replace(array("\r", "\n"), array('\r', '\n'), $x); } $hadError = false; foreach($test as $input => $expect) { $output = $input; Net_SMTP::quotedata($output); if ($output != $expect) { print "Error: input ".prettyprint($input).", output ".prettyprint($output).", expected ".prettyprint($expect)."\n"; $hadError = true; } } if (!$hadError) print 'Success!'; --EXPECT-- Success!