From 26b71486207ec213373da6fe3e390d275c131870 Mon Sep 17 00:00:00 2001 From: Ricky Rosario Date: Tue, 12 Apr 2011 15:23:10 -0400 Subject: [PATCH] All links in bio are now rel="nofollow". [bug 648774] --- apps/sumo/helpers.py | 8 +++++--- apps/sumo/parser.py | 12 ++++++++---- apps/users/templates/users/profile.html | 2 +- apps/users/tests/test_templates.py | 9 +++++++++ vendor | 2 +- 5 files changed, 24 insertions(+), 9 deletions(-) diff --git a/apps/sumo/helpers.py b/apps/sumo/helpers.py index 44ccd11bd..32f76d035 100644 --- a/apps/sumo/helpers.py +++ b/apps/sumo/helpers.py @@ -51,7 +51,7 @@ def url(viewname, *args, **kwargs): @register.function def unlocalized_url(viewname, *args, **kwargs): """Helper for Django's ``reverse`` in templates. - + Uses django's default reverse.""" return django_reverse(viewname, args=args, kwargs=kwargs) @@ -87,9 +87,11 @@ def urlparams(url_, hash=None, query_dict=None, **query): @register.filter -def wiki_to_html(wiki_markup, locale=settings.WIKI_DEFAULT_LANGUAGE): +def wiki_to_html(wiki_markup, locale=settings.WIKI_DEFAULT_LANGUAGE, + nofollow=False): """Wiki Markup -> HTML jinja2.Markup object""" - return jinja2.Markup(sumo.parser.wiki_to_html(wiki_markup, locale=locale)) + return jinja2.Markup(sumo.parser.wiki_to_html(wiki_markup, locale=locale, + nofollow=nofollow)) class Paginator(object): diff --git a/apps/sumo/parser.py b/apps/sumo/parser.py index e3cd032bb..5d27a29a8 100644 --- a/apps/sumo/parser.py +++ b/apps/sumo/parser.py @@ -35,9 +35,11 @@ IMAGE_PARAM_VALUES = { } -def wiki_to_html(wiki_markup, locale=settings.WIKI_DEFAULT_LANGUAGE): +def wiki_to_html(wiki_markup, locale=settings.WIKI_DEFAULT_LANGUAGE, + nofollow=False): """Wiki Markup -> HTML""" - return WikiParser().parse(wiki_markup, show_toc=False, locale=locale) + return WikiParser().parse(wiki_markup, show_toc=False, locale=locale, + nofollow=nofollow) def get_object_fallback(cls, title, locale, default=None, **kwargs): @@ -177,7 +179,8 @@ class WikiParser(Parser): self.registerInternalLinkHook('Image', self._hook_image_tag) def parse(self, text, show_toc=None, tags=None, attributes=None, - styles=None, locale=settings.WIKI_DEFAULT_LANGUAGE): + styles=None, locale=settings.WIKI_DEFAULT_LANGUAGE, + nofollow=False): """Given wiki markup, return HTML. Pass a locale to get all the hooks to look up Documents or Media @@ -191,7 +194,8 @@ class WikiParser(Parser): parser_kwargs = {'tags': tags} if tags else {} return super(WikiParser, self).parse(text, show_toc=show_toc, attributes=attributes or ALLOWED_ATTRIBUTES, - styles=styles or ALLOWED_STYLES, **parser_kwargs) + styles=styles or ALLOWED_STYLES, nofollow=nofollow, + **parser_kwargs) def _hook_internal_link(self, parser, space, name): """Parses text and returns internal link.""" diff --git a/apps/users/templates/users/profile.html b/apps/users/templates/users/profile.html index 33b678056..5fbb97893 100644 --- a/apps/users/templates/users/profile.html +++ b/apps/users/templates/users/profile.html @@ -71,7 +71,7 @@ {% if profile.bio %}

{{ _('About {user}')|f(user=display_name(profile.user)) }}

- {{ profile.bio|wiki_to_html }} + {{ profile.bio|wiki_to_html(nofollow=True) }}
{% endif %} diff --git a/apps/users/tests/test_templates.py b/apps/users/tests/test_templates.py index c53f379ca..2c7b261d1 100644 --- a/apps/users/tests/test_templates.py +++ b/apps/users/tests/test_templates.py @@ -333,6 +333,15 @@ class ViewProfileTests(TestCaseBase): eq_('Edit my profile', doc('#doc-tabs li:last').text()) self.client.logout() + def test_bio_links_nofollow(self): + profile = Profile.objects.get(user__id=47963) + profile.bio = 'http://getseo.com, [http://getseo.com]' + profile.save() + r = self.client.get(reverse('users.profile', args=[47963])) + eq_(200, r.status_code) + doc = pq(r.content) + eq_(2, len(doc('#bio a[rel="nofollow"]'))) + class PasswordChangeTests(TestCaseBase): fixtures = ['users.json'] diff --git a/vendor b/vendor index b52073f9d..c6d0cacfe 160000 --- a/vendor +++ b/vendor @@ -1 +1 @@ -Subproject commit b52073f9d013b11621133c020e8dbc041b8b3790 +Subproject commit c6d0cacfe7edaac8dd2f13bd3f1f1d2466f7a4fb