dcwatson / bbcode

A pure python bbcode parser and formatter.
BSD 2-Clause "Simplified" License
68 stars 17 forks source link

Leading slashes getting removed #3

Closed zauberparacelsus closed 11 years ago

zauberparacelsus commented 11 years ago

The bbcode parser is stripping the leading slashes out of links. Because of this, relative links cannot be used without additional hacking.

zauberparacelsus commented 11 years ago

I decided to just take a look at the code and fix it. On the second line of the body of the _render_url function, I added a check for if the first character of href was not a / mark.

        def _render_url(name, value, options, parent, context):
            href = options['url'] if (options and 'url' in options) else value
            if '://' not in href and href[0] != "/":
                href = 'http://' + href
            return '<a href="%s">%s</a>' % (self._replace(href, self.REPLACE_ESCAPE), value)
dcwatson commented 11 years ago

Thanks. That fix would work for paths that start with /, but not for relative paths (url=path/to/file) or filenames (url=test.html). I added some code in 3bcebab2eb0d8e76bc3c5f19ed95bc05242e1480 to add the missing http:// only for things that look like they start with a domain name. Also added some test cases.