pirave / postmarkup

Automatically exported from code.google.com/p/postmarkup
0 stars 0 forks source link

Attribute error when parsing malformed URL #20

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. Feed some plain text with an invalid URL of the form: http:\\something.com 
(i.e. use the wrong slashes) to postmarkup. 

What is the expected output? What do you see instead?

I would expect postmarkup to not try to produce an <a> tag for bad URL. However 
it does, and an AttributeError is seen instead. Here is the bottom part of a 
stack trace (the first level shown is my code calling postmarkup):

  ...
  File "legacy/management/commands/import_old_posts.py", line 103, in to_html
    return self.bb_parser.render_to_html(unphpbb(s), cosmetic_replace=False)
  File "/home/brian/coding/python/django/3rdparty/postmarkup.py", line 1259, in render_to_html
    node_text = node_text(i)
  File "/home/brian/coding/python/django/3rdparty/postmarkup.py", line 1120, in call
    return tag.render_open(parser, node_index)
  File "/home/brian/coding/python/django/3rdparty/postmarkup.py", line 285, in render_open
    domain = self._re_domain.search(uri.lower()).group(1)
AttributeError: 'NoneType' object has no attribute 'group'

What version of the product are you using? On what operating system?

SVN version, revision 66 on Ubuntu 10.04.

Please provide any additional information below.

I fixed it by applying the following diff to postmarkup.py

283a284,287
>         match = self._re_domain.search(uri.lower())
>         if match is None:
>             return u''
> 
285c289
<             domain = self._re_domain.search(uri.lower()).group(1)

---
>             domain = match.group(1)

Thanks for this great program!

Original issue reported on code.google.com by bgn...@gmail.com on 31 Dec 2010 at 5:47

GoogleCodeExporter commented 8 years ago
Thanks. Fixed in trunk.

Original comment by willmcgugan on 31 Dec 2010 at 11:48