From 791fdcc130291068eab4a8a44b4770edb2e93eb5 Mon Sep 17 00:00:00 2001 From: Matt Westcott Date: Mon, 18 Jan 2021 15:04:39 +0000 Subject: [PATCH] Add \n delimiter between url and max_width This prevents `get_embed_hash('https://example.com/embed', 400)` and `get_embed_hash('https://example.com/embed400')` from returning the same result. --- wagtail/embeds/embeds.py | 1 + wagtail/embeds/tests/test_embeds.py | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/wagtail/embeds/embeds.py b/wagtail/embeds/embeds.py index 9bee981905..9f2ee776a8 100644 --- a/wagtail/embeds/embeds.py +++ b/wagtail/embeds/embeds.py @@ -63,5 +63,6 @@ def get_embed_hash(url, max_width=None): h = md5() h.update(url.encode("utf-8")) if max_width is not None: + h.update(b"\n") h.update(str(max_width).encode("utf-8")) return h.hexdigest() diff --git a/wagtail/embeds/tests/test_embeds.py b/wagtail/embeds/tests/test_embeds.py index aeea8bac6d..55bf692e39 100644 --- a/wagtail/embeds/tests/test_embeds.py +++ b/wagtail/embeds/tests/test_embeds.py @@ -212,8 +212,8 @@ class TestEmbedHash(TestCase): def test_get_embed_hash(self): url = "www.test.com/1234" self.assertEqual(get_embed_hash(url), "9a4cfc187266026cd68160b5db572629") - self.assertEqual(get_embed_hash(url, 0), "be54b69772d5e086ec07748741455736") - self.assertEqual(get_embed_hash(url, 1), "601c15cca60eb068ebcc166b9587ed63") + self.assertEqual(get_embed_hash(url, 0), "946fb9597a6c74ab3cef1699eff7fde7") + self.assertEqual(get_embed_hash(url, 1), "427830227a86093b50417e11dbd2f28e") class TestChooser(TestCase, WagtailTestUtils):