Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

[1.1.X] Fixed #8758 -- Corrected handling of tag creation in feeds wh…

…en the URL contains a port number.

Partial backport of r12338 from trunk.

git-svn-id: http://code.djangoproject.com/svn/django/branches/releases/1.1.X@12340 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 4a1be98aee7aba994645d943af0a31aaab6ee11e 1 parent 2777cd3
@freakboy3742 freakboy3742 authored
View
16 django/utils/feedgenerator.py
@@ -19,8 +19,8 @@
http://diveintomark.org/archives/2004/02/04/incompatible-rss
"""
-import re
import datetime
+import urlparse
from django.utils.xmlutils import SimplerXMLGenerator
from django.utils.encoding import force_unicode, iri_to_uri
@@ -46,12 +46,16 @@ def rfc3339_date(date):
return date.strftime('%Y-%m-%dT%H:%M:%SZ')
def get_tag_uri(url, date):
- "Creates a TagURI. See http://diveintomark.org/archives/2004/05/28/howto-atom-id"
- tag = re.sub('^http://', '', url)
+ """
+ Creates a TagURI.
+
+ See http://diveintomark.org/archives/2004/05/28/howto-atom-id
+ """
+ url_split = urlparse.urlparse(url)
+ d = ''
if date is not None:
- tag = re.sub('/', ',%s:/' % date.strftime('%Y-%m-%d'), tag, 1)
- tag = re.sub('#', '/', tag)
- return u'tag:' + tag
+ d = ',%s' % date.strftime('%Y-%m-%d')
+ return u'tag:%s%s:%s/%s' % (url_split.hostname, d, url_split.path, url_split.fragment)
class SyndicationFeed(object):
"Base class for all syndication feeds. Subclasses should provide write()"
View
63 tests/regressiontests/utils/feedgenerator.py
@@ -0,0 +1,63 @@
+import datetime
+from unittest import TestCase
+
+from django.utils import feedgenerator, tzinfo
+
+class FeedgeneratorTest(TestCase):
+ """
+ Tests for the low-level syndication feed framework.
+ """
+
+ def test_get_tag_uri(self):
+ """
+ Test get_tag_uri() correctly generates TagURIs.
+ """
+ self.assertEqual(
+ feedgenerator.get_tag_uri('http://example.org/foo/bar#headline', datetime.date(2004, 10, 25)),
+ u'tag:example.org,2004-10-25:/foo/bar/headline')
+
+ def test_get_tag_uri_with_port(self):
+ """
+ Test that get_tag_uri() correctly generates TagURIs from URLs with port
+ numbers.
+ """
+ self.assertEqual(
+ feedgenerator.get_tag_uri('http://www.example.org:8000/2008/11/14/django#headline', datetime.datetime(2008, 11, 14, 13, 37, 0)),
+ u'tag:www.example.org,2008-11-14:/2008/11/14/django/headline')
+
+ def test_rfc2822_date(self):
+ """
+ Test rfc2822_date() correctly formats datetime objects.
+ """
+ self.assertEqual(
+ feedgenerator.rfc2822_date(datetime.datetime(2008, 11, 14, 13, 37, 0)),
+ "Fri, 14 Nov 2008 13:37:00 -0000"
+ )
+
+ def test_rfc2822_date_with_timezone(self):
+ """
+ Test rfc2822_date() correctly formats datetime objects with tzinfo.
+ """
+ self.assertEqual(
+ feedgenerator.rfc2822_date(datetime.datetime(2008, 11, 14, 13, 37, 0, tzinfo=tzinfo.FixedOffset(datetime.timedelta(minutes=60)))),
+ "Fri, 14 Nov 2008 13:37:00 +0100"
+ )
+
+ def test_rfc3339_date(self):
+ """
+ Test rfc3339_date() correctly formats datetime objects.
+ """
+ self.assertEqual(
+ feedgenerator.rfc3339_date(datetime.datetime(2008, 11, 14, 13, 37, 0)),
+ "2008-11-14T13:37:00Z"
+ )
+
+ def test_rfc3339_date_with_timezone(self):
+ """
+ Test rfc3339_date() correctly formats datetime objects with tzinfo.
+ """
+ self.assertEqual(
+ feedgenerator.rfc3339_date(datetime.datetime(2008, 11, 14, 13, 37, 0, tzinfo=tzinfo.FixedOffset(datetime.timedelta(minutes=120)))),
+ "2008-11-14T13:37:00+02:00"
+ )
+
View
1  tests/regressiontests/utils/tests.py
@@ -29,6 +29,7 @@
}
from dateformat import *
+from feedgenerator import *
class TestUtilsHtml(TestCase):
Please sign in to comment.
Something went wrong with that request. Please try again.