From 001b0710c7433300c141459bf25aecf57e7c6434 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9gis=20Hanol?= Date: Mon, 16 Apr 2018 15:41:45 +0200 Subject: [PATCH] FIX: don't add diff classes more than once --- lib/discourse_diff.rb | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/discourse_diff.rb b/lib/discourse_diff.rb index c1971ed7108..89d293e4319 100644 --- a/lib/discourse_diff.rb +++ b/lib/discourse_diff.rb @@ -184,8 +184,13 @@ class DiscourseDiff # add it right before the ">" html_or_text.insert(index_of_next_chevron, " class=\"diff-#{klass}\"") else - # we have a class, insert it at the beginning - html_or_text.insert(index_of_class + "class=".length + 1, "diff-#{klass} ") + # we have a class, insert it at the beginning if not already present + classes = html_or_text[/class=(["'])([^\1]*)\1/, 2] + if classes.include?("diff-#{klass}") + html_or_text + else + html_or_text.insert(index_of_class + "class=".length + 1, "diff-#{klass} ") + end end else "<#{klass}>#{html_or_text}"