Opened 8 years ago

Closed 7 years ago

Last modified 7 years ago

#8758 closed (fixed)

get_tag_uri in /django/utils/ 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:


The following function:

def get_tag_uri(url, date):
    "Creates a TagURI. See"
    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


... breaks for domain names with a port number, such as as this produces the following TAG value:


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

Download all attachments as: .zip

Change History (8)

comment:1 Changed 8 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 8 years ago by arthurk

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

Changed 8 years ago by arthurk

Changed 8 years ago by arthurk

regression test

comment:3 Changed 8 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 8 years ago by arthurk

  • Triage Stage changed from Unreviewed to Accepted

comment:5 Changed 7 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 7 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