FIX: Ignore query parameters when displaying counter on internal links

FIX: Ignore query parameters when displaying counter on internal links

This matches the server-side behaviour, so that the links display counters correctly

From 8aff99761aec7cb1b9ad14c99a88c41ef3add11f Mon Sep 17 00:00:00 2001
From: David Taylor <david@taylorhq.com>
Date: Wed, 5 Dec 2018 18:29:54 +0000
Subject: [PATCH] FIX: Ignore query parameters when displaying counter on
 internal links

This matches the server-side behaviour, so that the links display counters correctly

diff --git a/app/assets/javascripts/discourse/widgets/post-cooked.js.es6 b/app/assets/javascripts/discourse/widgets/post-cooked.js.es6
index bbbf95d..bf3a323 100644
--- a/app/assets/javascripts/discourse/widgets/post-cooked.js.es6
+++ b/app/assets/javascripts/discourse/widgets/post-cooked.js.es6
@@ -104,6 +104,11 @@ export default class PostCooked {
           valid = href.indexOf(lc.url) >= 0;
         }
 
+        // Match server-side behaviour for internal links with query params
+        if (lc.internal && /\?/.test(href)) {
+          valid = href.split("?")[0] === lc.url;
+        }
+
         // don't display badge counts on category badge & oneboxes (unless when explicitely stated)
         if (valid && isValidLink($link)) {
           const title = I18n.t("topic_map.clicks", { count: lc.clicks });

GitHub

1 Like

This commit has been mentioned on Discourse Meta. There might be relevant details there:

I know it is pretty annoying to write but I would like to see a test for this magic.

2 Likes

DEV: Add test for 8aff99761ae.