Browse Source

Fix badges for tags containing special characters. Fixes #240, #237

pull/230/head
Pēteris Caune 6 years ago
parent
commit
b528b23996
No known key found for this signature in database GPG Key ID: E28D7679E9A9EDE2
6 changed files with 47 additions and 9 deletions
  1. +4
    -0
      CHANGELOG.md
  2. +11
    -0
      hc/api/tests/test_badge.py
  3. +17
    -3
      hc/api/urls.py
  4. +14
    -2
      hc/front/tests/test_badges.py
  5. +0
    -3
      hc/front/views.py
  6. +1
    -1
      templates/front/badges.html

+ 4
- 0
CHANGELOG.md View File

@ -6,6 +6,10 @@ All notable changes to this project will be documented in this file.
### Improvements ### Improvements
- Add the `prunetokenbucket` management command - Add the `prunetokenbucket` management command
### Bug Fixes
- Fix badges for tags containing special characters (#240, #237)
## 1.7.0 - 2019-05-02 ## 1.7.0 - 2019-05-02
### Improvements ### Improvements


+ 11
- 0
hc/api/tests/test_badge.py View File

@ -60,3 +60,14 @@ class BadgeTestCase(BaseTestCase):
r = self.client.get(self.json_url) r = self.client.get(self.json_url)
self.assertContains(r, "late") self.assertContains(r, "late")
def test_it_handles_special_characters(self):
self.check.tags = "db@dc1"
self.check.save()
sig = base64_hmac(str(self.project.badge_key), "db@dc1", settings.SECRET_KEY)
sig = sig[:8]
url = "/badge/%s/%s/db%%2540dc1.svg" % (self.project.badge_key, sig)
r = self.client.get(url)
self.assertEqual(r.status_code, 200)

+ 17
- 3
hc/api/urls.py View File

@ -1,7 +1,21 @@
from django.urls import path
from urllib.parse import quote, unquote
from django.urls import path, register_converter
from hc.api import views from hc.api import views
class QuoteConverter:
regex = '[\w%~_.-]+'
def to_python(self, value):
return unquote(value)
def to_url(self, value):
return quote(value, safe="")
register_converter(QuoteConverter, 'quoted')
urlpatterns = [ urlpatterns = [
path('ping/<uuid:code>/', views.ping, name="hc-ping-slash"), path('ping/<uuid:code>/', views.ping, name="hc-ping-slash"),
path('ping/<uuid:code>', views.ping, name="hc-ping"), path('ping/<uuid:code>', views.ping, name="hc-ping"),
@ -17,13 +31,13 @@ urlpatterns = [
path('api/v1/channels/', views.channels), path('api/v1/channels/', views.channels),
path('badge/<slug:badge_key>/<slug:signature>/<slug:tag>.svg', views.badge,
path('badge/<slug:badge_key>/<slug:signature>/<quoted:tag>.svg', views.badge,
name="hc-badge"), name="hc-badge"),
path('badge/<slug:badge_key>/<slug:signature>.svg', views.badge, path('badge/<slug:badge_key>/<slug:signature>.svg', views.badge,
{"tag": "*"}, name="hc-badge-all"), {"tag": "*"}, name="hc-badge-all"),
path('badge/<slug:badge_key>/<slug:signature>/<slug:tag>.json', views.badge,
path('badge/<slug:badge_key>/<slug:signature>/<quoted:tag>.json', views.badge,
{"format": "json"}, name="hc-badge-json"), {"format": "json"}, name="hc-badge-json"),
path('badge/<slug:badge_key>/<slug:signature>.json', views.badge, path('badge/<slug:badge_key>/<slug:signature>.json', views.badge,


hc/accounts/tests/test_badges.py → hc/front/tests/test_badges.py View File


+ 0
- 3
hc/front/views.py View File

@ -528,9 +528,6 @@ def badges(request, code):
urls = [] urls = []
for tag in sorted_tags: for tag in sorted_tags:
if not re.match("^[\w-]+$", tag) and tag != "*":
continue
urls.append({ urls.append({
"tag": tag, "tag": tag,
"svg": get_badge_url(project.badge_key, tag), "svg": get_badge_url(project.badge_key, tag),


+ 1
- 1
templates/front/badges.html View File

@ -1,7 +1,7 @@
{% extends "base.html" %} {% extends "base.html" %}
{% load compress static hc_extras %} {% load compress static hc_extras %}
{% block title %}Account Settings - {% site_name %}{% endblock %}
{% block title %}Status Badges - {% site_name %}{% endblock %}
{% block content %} {% block content %}
<div class="row"> <div class="row">


Loading…
Cancel
Save