From dc611248879639de5901b71bf8c8112ed51f15cb Mon Sep 17 00:00:00 2001
From: jmorahan <jmorahan@58170.no-reply.drupal.org>
Date: Tue, 4 Feb 2014 00:14:57 -0500
Subject: [PATCH] Issue #1951736 by twistor, John Morahan: Discovery sometimes
 fails.

---
 feeds.info                 |  1 +
 libraries/http_request.inc |  6 ++++-
 tests/http_request.test    | 54 ++++++++++++++++++++++++++++++++++++++
 3 files changed, 60 insertions(+), 1 deletion(-)
 create mode 100644 tests/http_request.test

diff --git a/feeds.info b/feeds.info
index 1d5590f8..0ce45e05 100644
--- a/feeds.info
+++ b/feeds.info
@@ -49,6 +49,7 @@ files[] = tests/feeds_processor_user.test
 files[] = tests/feeds_scheduler.test
 files[] = tests/feeds_mapper_link.test
 files[] = tests/feeds_mapper_taxonomy.test
+files[] = tests/http_request.test
 files[] = tests/parser_csv.test
 
 ; Views integration
diff --git a/libraries/http_request.inc b/libraries/http_request.inc
index 7e70fe6c..852dd4b8 100644
--- a/libraries/http_request.inc
+++ b/libraries/http_request.inc
@@ -351,7 +351,11 @@ function http_request_find_feeds($html) {
     preg_match_all(HTTP_REQUEST_PCRE_TAG_ATTRIBUTES, $link_tag, $attributes, PREG_SET_ORDER);
     foreach ($attributes as $attribute) {
       // Find the key value pairs, attribute[1] is key and attribute[2] is the
-      // value.
+      // value.  However, if the link tag used single quotes, the value might
+      // be in attribute[3] instead.
+      if (empty($attribute[2])) {
+        $attribute[2] = $attribute[3];
+      }
       if (!empty($attribute[1]) && !empty($attribute[2])) {
         $candidate[drupal_strtolower($attribute[1])] = drupal_strtolower(decode_entities($attribute[2]));
       }
diff --git a/tests/http_request.test b/tests/http_request.test
new file mode 100644
index 00000000..de6b1e1d
--- /dev/null
+++ b/tests/http_request.test
@@ -0,0 +1,54 @@
+<?php
+
+/**
+ * @file
+ * Tests for http_request.inc.
+ */
+
+/**
+ * Tests for the http library.
+ */
+class FeedsHTTPRequestTestCase extends FeedsUnitTestHelper {
+  public static function getInfo() {
+    return array(
+      'name' => 'HTTP library',
+      'description' => 'Tests for Feeds HTTP library.',
+      'group' => 'Feeds',
+    );
+  }
+
+  public function setUp() {
+    parent::setUp();
+    feeds_include_library('http_request.inc', 'http_request');
+  }
+
+  /**
+   * Tests http_request_find_feeds().
+   */
+  public function testHTTPRequestFindFeeds() {
+    $html = <<<EOF
+<html>
+  <head>
+    <title>Welcome to Example.com</title>
+    <link rel="stylesheet" type="text/css" media="screen, projection" href="/stuff.css" >
+    <link rel="search"    title="Something" href="//example.com/search">
+    <link rel="alternate" title="Something RSS" href="http://example.com/rss.xml" type="application/rss+xml">
+    <link rel="shortcut icon" href="/favicon.ico" type="image/x-icon">
+  </head>
+  <body>
+    This is a body.
+  </body>
+</html
+EOF;
+
+    $links = http_request_find_feeds($html);
+    $this->assertEqual(count($links), 1);
+    $this->assertEqual($links[0], 'http://example.com/rss.xml');
+
+    // Test single quoted HTML.
+    $links = http_request_find_feeds(str_replace('"', "'", $html));
+    $this->assertEqual(count($links), 1);
+    $this->assertEqual($links[0], 'http://example.com/rss.xml');
+  }
+
+}
-- 
GitLab