[cgi-wiki-dev] Formatter::Pod and line endings

Tom Insam cgi-wiki-dev@earth.li
Fri, 29 Oct 2004 09:43:17 +0100


--Apple-Mail-2-473113684
Content-Transfer-Encoding: 7bit
Content-Type: text/plain;
	charset=US-ASCII;
	format=flowed

Whilst re-hosting the Wiki::Toolkit development wiki (it's now at 
http://movieos.org/wiki-toolkit/) we discovered that 
CGI::Wiki::Formatter::Pod requires the line-endings of the thing it's 
formatting to be unix-style. This wasn't a problem till I started 
pointing Safari at it - you're clearly all firefox users - but would be 
under 'normal' usage.

Rather than fix the formatter, I think it's probably better to ensure 
that whatever formatter we use is always passed unix line endings. This 
patch (to CGI::Wiki) does this.

--Apple-Mail-2-473113684
Content-Transfer-Encoding: 7bit
Content-Type: application/octet-stream;
	x-unix-mode=0664;
	name="line_endings.patch"
Content-Disposition: attachment;
	filename=line_endings.patch

Index: lib/CGI/Wiki.pm
===================================================================
--- lib/CGI/Wiki.pm	(revision 1333)
+++ lib/CGI/Wiki.pm	(working copy)
@@ -861,6 +861,10 @@
 sub format {
     my ( $self, $raw, $metadata ) = @_;
     my $formatter = $self->formatter;
+
+    # Ensure unix line endings
+    $raw =~ s/(\012|\015\012?)/\012/g;
+
     # Add on $self to the call so the formatter can access things like whether
     # a linked-to node exists, etc.
     my $result = $formatter->format( $raw, $self, $metadata );

--Apple-Mail-2-473113684
Content-Transfer-Encoding: 7bit
Content-Type: text/plain;
	charset=US-ASCII;
	format=flowed



Actually, now I think about it, would we prefer a patch that ensures 
that the node contents as stored in the database always have unix line 
endings, ie move this match to before the node store operation?

--Apple-Mail-2-473113684
Content-Transfer-Encoding: 7bit
Content-Type: application/octet-stream;
	x-unix-mode=0664;
	name="other_line_endings.patch"
Content-Disposition: attachment;
	filename=other_line_endings.patch

Index: lib/CGI/Wiki.pm
===================================================================
--- lib/CGI/Wiki.pm	(revision 1340)
+++ lib/CGI/Wiki.pm	(working copy)
@@ -829,6 +829,9 @@
         @links_to = keys %unique;
     }
 
+    # Ensure unix line endings
+    $content =~ s/(\012|\015\012?)/\012/g;
+
     my %data = ( node     => $node,
 		 content  => $content,
 		 checksum => $checksum,

--Apple-Mail-2-473113684
Content-Transfer-Encoding: 7bit
Content-Type: text/plain;
	charset=US-ASCII;
	format=flowed



tom

--Apple-Mail-2-473113684--