Deprioritize those with type=text/plain when there are multiple 
rel=alternative links. Fixes tests,  plus some refactoring.

        Patch by kareila. 

diffs (61 lines):

diff -r 2a333cd49a4b -r 0c0b0efdf409 cgi-bin/LJ/ParseFeed.pm
--- a/cgi-bin/LJ/ParseFeed.pm   Tue Sep 21 18:08:28 2010 +0800
+++ b/cgi-bin/LJ/ParseFeed.pm   Tue Sep 21 21:18:16 2010 +0800
@@ -221,14 +221,15 @@ sub startaccum {
     $data = ""; # defining $data triggers accumulation
     $ddepth = 1;
 
-    $dholder = undef 
-        unless $name;
-    # if $name is a scalarref, it's actually our $dholder
-    if (ref($name) eq 'SCALAR') {
-        $dholder = $name;
+    if ( $name ) {
+        # if $name is a scalarref, it's actually our $dholder
+        if ( ref $name eq 'SCALAR' ) {
+            $dholder = $name;
+        } else {
+            $dholder = $item ? \$item->{$name} : \$feed->{$name};
+        }
     } else {
-        $dholder = ($item ? \$item->{$name} : \$feed->{$name})
-            if $name;
+        $dholder = undef;  # no $name
     }
     return;
 }
@@ -303,6 +304,15 @@ sub StartTag {
                 swallow();
                 last TAGS;
             }
+
+            # if multiple alternates are specified, prefer the one
+            # that doesn't have a type of text/plain.
+            # see also t/parsefeed-atom-link2.t
+            if ( $holder->{link} && $_{type} && $_{type} eq 'text/plain' ) {
+                swallow();
+                last TAGS;
+            }
+
             $holder->{'link'} = $_{'href'};
             return err("No href attribute in <link>")
                 unless $holder->{'link'};
diff -r 2a333cd49a4b -r 0c0b0efdf409 t/parsefeed-atom-link2.t
--- a/t/parsefeed-atom-link2.t  Tue Sep 21 18:08:28 2010 +0800
+++ b/t/parsefeed-atom-link2.t  Tue Sep 21 21:18:16 2010 +0800
@@ -5,12 +5,11 @@ use LJ::ParseFeed;
 use LJ::ParseFeed;
 require 'ljlib.pl';
 
-#plan tests => ;
-plan skip_all => 'Fix this test!';
+plan tests => 8;
 
 #  These tests are of the correct identification of an "alternate" link.
-#  We assume here that an HTML alternate link is preferred over text/plain, 
despite the
-# fact that preferring the latter is technically allowed.
+#  We assume here that an HTML alternate link is preferred over text/plain,
+#  despite the fact that preferring the latter is technically allowed.
 
 # This is taken verbatim from James Snell's set of test cases:
 #    <http://www.snellspace.com/public/linktests.xml>
_______________________________________________
dw-changelog mailing list
[email protected]
http://lists.dwscoalition.org/mailman/listinfo/dw-changelog

Reply via email to