Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Improve quotedata()'s handling of leading dots.

Bug: 18819
  • Loading branch information...
commit 0f5f8556ba89725fedcd9b9a72461ef8d84b7af6 1 parent 9ada985
@jparise jparise authored
Showing with 28 additions and 21 deletions.
  1. +5 −7 SMTP.php
  2. +3 −2 package.xml
  3. +20 −12 tests/quotedata.phpt
View
12 SMTP.php
@@ -1004,14 +1004,12 @@ function rcptTo($recipient, $params = null)
*/
function quotedata(&$data)
{
- /* Change Unix (\n) and Mac (\r) linefeeds into
- * Internet-standard CRLF (\r\n) linefeeds. */
- $data = preg_replace(array('/(?<!\r)\n/','/\r(?!\n)/'), "\r\n", $data);
-
/* Because a single leading period (.) signifies an end to the
- * data, legitimate leading periods need to be "doubled"
- * (e.g. '..'). */
- $data = str_replace("\n.", "\n..", $data);
+ * data, legitimate leading periods need to be "doubled" ('..'). */
+ $data = preg_replace('/^\./m', '..', $data);
+
+ /* Change Unix (\n) and Mac (\r) linefeeds into CRLF's (\r\n). */
+ $data = preg_replace('/(?:\r\n|\n|\r(?!\n))/', "\r\n", $data);
}
/**
View
5 package.xml
@@ -19,8 +19,8 @@
<email>chuck@horde.org</email>
<active>yes</active>
</lead>
- <date>2011-08-13</date>
- <time>10:00:00</time>
+ <date>2011-09-18</date>
+ <time>17:00:00</time>
<version>
<release>1.6.2</release>
<api>1.2.0</api>
@@ -31,6 +31,7 @@
</stability>
<license uri="http://www.php.net/license/3_01.txt">PHP License</license>
<notes>- Update to Auth_SASL 1.0.5 and its new IANA names. (Request 18837)
+- Improve quotedata()'s handling of leading dots. (Bug 18819)
</notes>
<contents>
<dir baseinstalldir="Net" name="/">
View
32 tests/quotedata.phpt
@@ -1,5 +1,5 @@
--TEST--
-Net_SMTP: quotedata() \n | \r => \r\n replacement
+Net_SMTP: quotedata()
--FILE--
<?php
@@ -7,6 +7,7 @@ error_reporting(E_ALL);
require_once 'Net/SMTP.php';
$tests = array(
+ /* Newlines */
"\n" => "\r\n",
"\r\n" => "\r\n",
"\nxx" => "\r\nxx",
@@ -37,26 +38,33 @@ $tests = array(
"xx\r\r" => "xx\r\n\r\n",
"xx\rxx\nxx\r\nxx" => "xx\r\nxx\r\nxx\r\nxx",
"\r\r\n\n" => "\r\n\r\n\r\n",
+
+ /* Dots */
+ "." => "..",
+ "xxx\n." => "xxx\r\n..",
+ "xxx\n.\nxxx" => "xxx\r\n..\r\nxxx",
+ "xxx.\n.xxx" => "xxx.\r\n..xxx",
);
-$hadError = false;
-foreach ($tests as $input => $expect) {
+function literal($x)
+{
+ return str_replace(array("\r", "\n"), array('\r', '\n'), $x);
+}
+
+$error = false;
+foreach ($tests as $input => $expected) {
$output = $input;
Net_SMTP::quotedata($output);
- if ($output != $expect) {
- echo "Error: input " . prettyprint($input) . ", output " . prettyprint($output) . ", expected " . prettyprint($expect) . "\n";
- $hadError = true;
+ if ($output != $expected) {
+ printf("Error: '%s' => '%s' (expected: '%s')",
+ literal($input), literal($output), literal($expected));
+ $error = true;
}
}
-if (!$hadError) {
+if (!$error) {
echo "success\n";
}
-function prettyprint($x)
-{
- return str_replace(array("\r", "\n"), array('\r', '\n'), $x);
-}
-
--EXPECT--
success

0 comments on commit 0f5f855

Please sign in to comment.
Something went wrong with that request. Please try again.