From 40b9532668b5e4d956c7be15f721be41d3defa3e Mon Sep 17 00:00:00 2001
From: Aymeric Augustin <aymeric.augustin@m4x.org>
Date: Fri, 18 Nov 2011 22:54:24 +0000
Subject: [PATCH] Fixed #16753 -- Supported network-path references in the
 syndication framework. Thanks cato for the report and patch.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@17108 bcc190cf-cafb-0310-a4f2-bffc1f526a37
---
 django/contrib/syndication/views.py        | 10 +++++-----
 tests/regressiontests/syndication/tests.py |  4 ++++
 2 files changed, 9 insertions(+), 5 deletions(-)

diff --git a/django/contrib/syndication/views.py b/django/contrib/syndication/views.py
index a6e18e3cd8..2480ff6caa 100644
--- a/django/contrib/syndication/views.py
+++ b/django/contrib/syndication/views.py
@@ -9,15 +9,15 @@ from django.utils.html import escape
 from django.utils.timezone import is_naive
 
 def add_domain(domain, url, secure=False):
-    if not (url.startswith('http://')
+    protocol = 'https' if secure else 'http'
+    if url.startswith('//'):
+        # Support network-path reference (see #16753) - RSS requires a protocol
+        url = '%s:%s' % (protocol, url)
+    elif not (url.startswith('http://')
             or url.startswith('https://')
             or url.startswith('mailto:')):
         # 'url' must already be ASCII and URL-quoted, so no need for encoding
         # conversions here.
-        if secure:
-            protocol = 'https'
-        else:
-            protocol = 'http'
         url = iri_to_uri(u'%s://%s%s' % (protocol, domain, url))
     return url
 
diff --git a/tests/regressiontests/syndication/tests.py b/tests/regressiontests/syndication/tests.py
index 14dcd0a471..95b4efb4f4 100644
--- a/tests/regressiontests/syndication/tests.py
+++ b/tests/regressiontests/syndication/tests.py
@@ -305,3 +305,7 @@ class SyndicationFeedTest(FeedTestCase):
             views.add_domain('example.com', 'mailto:uhoh@djangoproject.com'),
             'mailto:uhoh@djangoproject.com'
         )
+        self.assertEqual(
+            views.add_domain('example.com', '//example.com/foo/?arg=value'),
+            'http://example.com/foo/?arg=value'
+        )