Mail\Headers.php: Adjust regex for field name to RFC 5322 #4224

Closed
wants to merge 2 commits into
from
View
4 library/Zend/Mail/Header/GenericHeader.php
@@ -76,9 +76,9 @@ public function setFieldName($fieldName)
$fieldName = str_replace(' ', '-', ucwords(str_replace(array('_', '-'), ' ', $fieldName)));
// Validate what we have
- if (!preg_match('/^[a-z][a-z0-9-]*$/i', $fieldName)) {
+ if (!preg_match('/^[\x21-\x39\x3B-\x7E]*$/i', $fieldName)) {
throw new Exception\InvalidArgumentException(
- 'Header name must start with a letter, and consist of only letters, numbers and dashes.'
+ 'Header name must be composed of printable US-ASCII characters, except colon.'
);
}
View
2 library/Zend/Mail/Headers.php
@@ -70,7 +70,7 @@ public static function fromString($string, $EOL = self::EOL)
// iterate the header lines, some might be continuations
foreach (explode($EOL, $string) as $line) {
// check if a header name is present
- if (preg_match('/^(?P<name>[^()><@,;:\"\\/\[\]?=}{ \t]+):.*$/', $line, $matches)) {
+ if (preg_match('/^(?P<name>[\x21-\x39\x3B-\x7E]+):.*$/', $line, $matches)) {
if ($currentLine) {
// a header name was present, then store the current complete line
$headers->addHeaderLine($currentLine);