[dev] Data::imc should split on [\r\n], not just \n

John Morrissey jwm at horde.net
Tue Jan 14 12:22:50 PST 2003


On Tue, Jan 14, 2003 at 11:00:08AM +0100, Jan Schneider wrote:
% >From the iCal RFC:
% 
% The content information associated with an iCalendar object is
%    formatted using a syntax similar to that defined by [RFC 2425]. That
%    is, the content information consists of CRLF-separated content lines.
% 
% RFC 2425 defines the format for RFC 2426 files (vCard). Summary: Data::imc
% (intended to deal with both formats) should always produce CRLF and be
% smart and read both CRLF and LF, perhaps even CR for buggy Mac clients.

Ok, patch attached.

This also cleans up a couple other minor things; the "_qouteAndFold"
function name, line-splitting consistency and (around like 235) code that
looks like it will insert double-newlines where only a single is needed.

john
-- 
John Morrissey          _o            /\         ----  __o
jwm at horde.net        _-< \_          /  \       ----  <  \,
www.horde.net/    __(_)/_(_)________/    \_______(_) /_(_)__
-------------- next part --------------
Index: icalendar.php
===================================================================
RCS file: /repository/horde/lib/Data/icalendar.php,v
retrieving revision 1.14
diff -u -u -r1.14 icalendar.php
--- icalendar.php	12 Jan 2003 15:43:24 -0000	1.14
+++ icalendar.php	14 Jan 2003 17:21:51 -0000
@@ -102,7 +102,7 @@
                 if (!empty($val)) {
                     // Basic encoding. Newlines for now; more work
                     // here to make this RFC-compliant.
-                    $file .= $key . ':' .  $this->_qouteAndFold($val) . $newline;
+                    $file .= $key . ':' .  $this->_quoteAndFold($val) . $newline;
                 }
             }
             $file .= "END:VEVENT\n";
Index: imc.php
===================================================================
RCS file: /repository/horde/lib/Data/imc.php,v
retrieving revision 1.16
diff -u -u -r1.16 imc.php
--- imc.php	13 Jan 2003 22:03:52 -0000	1.16
+++ imc.php	14 Jan 2003 17:21:51 -0000
@@ -22,7 +22,7 @@
 
     function import($text)
     {
-        $lines = preg_split('/[\r\n]+/', $text);
+        $lines = preg_split('/(\r\n|\n|\r)/', $text);
         $data = array();
 
         // Unfolding.
@@ -201,12 +201,14 @@
         return count($this->_objects);
     }
 
-    function _qouteAndFold($string)
+    function _quoteAndFold($string)
     {
-        $lines = preg_split('(\r\n|\n|\r)', rtrim($string));
-        $newline = $this->getNewline();
-        $valueLines = array();
+        /* According to RFC 2425, we should always use CRLF-terminated
+           lines. */
+        $newline = "\r\n";
 
+        $lines = preg_split('/(\r\n|\n|\r)/', rtrim($string));
+        $valueLines = array();
         foreach ($lines as $line) {
             if (strlen($line) > 75) {
                 $foldedline = '';
@@ -232,7 +234,7 @@
                 $valueLines[] = $line;
             }
         }
-        return implode("\\n" . $newline ." ", $valueLines);
+        return implode($newline . " ", $valueLines) . $newline;
     }
 
 }


More information about the dev mailing list