Skip to content

Commit

Permalink
Tag Tracking+: Fix crash when tags contain special characters (#1020)
Browse files Browse the repository at this point in the history
  • Loading branch information
marcustyphoon authored Mar 15, 2023
1 parent e8e7176 commit 1e00874
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/scripts/tag_tracking_plus.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ const refreshCount = async function (tag) {
}
}
} = await apiFetch(
`/v2/hubs/${tag}/timeline`,
`/v2/hubs/${encodeURIComponent(tag)}/timeline`,
{ queryParams: { limit: 20, sort: 'recent' } }
);

Expand All @@ -58,7 +58,11 @@ const refreshCount = async function (tag) {
const unreadCountString = `${unreadCount}${showPlus ? '+' : ''}`;

[document, ...(!sidebarItem || document.contains(sidebarItem) ? [] : [sidebarItem])]
.flatMap(node => [...node.querySelectorAll(`[data-count-for="#${tag}"]`)])
.flatMap(node =>
[...node.querySelectorAll('[data-count-for]')].filter(
({ dataset: { countFor } }) => countFor === `#${tag}`
)
)
.filter((value, index, array) => array.indexOf(value) === index)
.forEach(unreadCountElement => {
unreadCountElement.textContent = unreadCountString;
Expand Down Expand Up @@ -149,7 +153,7 @@ export const main = async function () {
title: 'Tag Tracking+',
rows: trackedTags.map(tag => ({
label: `#${tag}`,
href: `/tagged/${tag}?sort=recent`,
href: `/tagged/${encodeURIComponent(tag)}?sort=recent`,
onclick: onClickNavigate,
count: '\u22EF'
}))
Expand Down

0 comments on commit 1e00874

Please sign in to comment.