Opened 16 years ago

Closed 14 years ago

Last modified 14 years ago

#8758 closed (fixed)

get_tag_uri in /django/utils/feedgenerator.py breaks with port numbers

Reported by: nslater Owned by: Arthur Koziel
Component: contrib.syndication Version: 1.0
Severity: Keywords:
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

The following function:

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)
    if date is not None:
        tag = re.sub('/', ',%s:/' % date.strftime('%Y-%m-%d'), tag, 1)
    tag = re.sub('#', '/', tag)
    return u'tag:' + tag
}}

- http://code.djangoproject.com/browser/django/trunk/django/utils/feedgenerator.py#L48

... breaks for domain names with a port number, such as http://example.org:8080/ as this produces the following TAG value:

{{{
tag:example.org:8080,2007-09-21:/
}}}

From http://feedvalidator.org/docs/error/InvalidTAG.html and http://tools.ietf.org/html/rfc4151#section-2.1 you can see that the TAG URI should not contain the port number.

The following patch should be able to extract the domain name from the link:

{{{
-    tag = re.sub('^http://', '', url)
+    tag = str(urllib.splitport(urllib.splithost(urllib.splittype(url)[1])[0])[0])
}}}

Attachments (2)

8758_feedgenerator.diff (1.7 KB ) - added by Arthur Koziel 16 years ago.
feedgenerator.py (340 bytes ) - added by Arthur Koziel 16 years ago.
regression test

Download all attachments as: .zip

Change History (8)

comment:1 by Daniel Pope <dan@…>, 16 years ago

Why not use urlparse.urlparse(url).hostname ?

comment:2 by Arthur Koziel, 16 years ago

Owner: changed from nobody to Arthur Koziel
Status: newassigned

by Arthur Koziel, 16 years ago

Attachment: 8758_feedgenerator.diff added

by Arthur Koziel, 16 years ago

Attachment: feedgenerator.py added

regression test

comment:3 by Arthur Koziel, 16 years ago

Version: SVN1.0

I added a diff and a unit test for a new get_tag_uri method which relies on urlparse instead of going through some regular expressions. Please review.

comment:4 by Arthur Koziel, 16 years ago

Triage Stage: UnreviewedAccepted

comment:5 by Russell Keith-Magee, 14 years ago

Resolution: fixed
Status: assignedclosed

(In [12338]) Fixed #6188, #6304, #6618, #6969, #8758, #8989, #10334, #11069, #11973 and #12403 -- Modified the syndication framework to use class-based views. Thanks to Ben Firshman for his work on this patch.

comment:6 by Russell Keith-Magee, 14 years ago

(In [12340]) [1.1.X] Fixed #8758 -- Corrected handling of tag creation in feeds when the URL contains a port number.

Partial backport of r12338 from trunk.

Note: See TracTickets for help on using tickets.
Back to Top