Skip to content

Conversation

nullchristo
Copy link
Contributor

@nullchristo nullchristo commented Aug 18, 2025

Remove duplicate entries (or repeats of the main tag) from the additional tags in the tags/intersection path.

This was causing unexpected behavior when the main tag was repeated again in the additional tags (which isn't typically possible by the core UI, but is possible in custom plugins or by directly editing the URL).

See https://meta.discourse.org/t/377740

Comment on lines 169 to 175
params[:additional_tag_ids] = (
if additional_tags_trimmed.present?
additional_tags_trimmed.join("/")
else
nil
end
)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
params[:additional_tag_ids] = (
if additional_tags_trimmed.present?
additional_tags_trimmed.join("/")
else
nil
end
)
if additional_tags_trimmed.present?
params[:additional_tag_ids] = additional_tags_trimmed.join("/")
end

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm... In case params[:additional_tag_ids] was already set, and the duplicate removal logic removes all entries (emptying additional_tags_trimmed, I need to clear params[:additional_tag_ids], which is why I'm setting it to nil explicitly here.

For instance, if params[:tag_id] = "tag1" and params[:additional_tag_ids] = "tag1", then I want to end up with params[:additional_tag_ids] = nil.

Maybe there's still a cleaner way than what I wrote?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like it's enough to do params[:additional_tag_ids] = additional_tags_trimmed&.join("/"). Was thinking I needed to set the param to nil but setting it to "" (in case the array is empty) works just as well to clear the param.

@nullchristo nullchristo merged commit 459a5f2 into main Aug 19, 2025
16 checks passed
@nullchristo nullchristo deleted the fix/intersection-remove-duplicate-tags branch August 19, 2025 14:58
yuriyaran pushed a commit that referenced this pull request Aug 21, 2025
Remove duplicate entries (or repeats of the main tag) from the
additional tags in the tags/intersection path.

This was causing unexpected behavior when the main tag was repeated
again in the additional tags (which isn't typically possible by the core
UI, but is possible in custom plugins or by directly editing the URL).

See https://meta.discourse.org/t/377740
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants