Opened 7 years ago

Closed 5 years ago

Last modified 5 years ago

#8758 closed (fixed)

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

Reported by: nslater Owned by: arthurk
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: UI/UX:

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 arthurk 7 years ago.
feedgenerator.py (340 bytes) - added by arthurk 7 years ago.
regression test

Download all attachments as: .zip

Change History (8)

comment:1 Changed 7 years ago by Daniel Pope <dan@…>

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

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

comment:2 Changed 7 years ago by arthurk

  • Owner changed from nobody to arthurk
  • Status changed from new to assigned

Changed 7 years ago by arthurk

Changed 7 years ago by arthurk

regression test

comment:3 Changed 7 years ago by arthurk

  • Version changed from SVN to 1.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 Changed 7 years ago by arthurk

  • Triage Stage changed from Unreviewed to Accepted

comment:5 Changed 5 years ago by russellm

  • Resolution set to fixed
  • Status changed from assigned to closed

(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 Changed 5 years ago by russellm

(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