FIX: URL encode tag name (#11393)

Tags with emoji in the name were failing to redirect via permalink
handling. This commit percent encodes the emoji name which fixes
the issue.

https://meta.discourse.org/t/permalinks-not-working-in-unicode-tags/171757/
This commit is contained in:
Arpit Jalan
2020-12-02 12:36:41 +05:30
committed by GitHub
parent 28032eaf38
commit 86feaec9be
2 changed files with 9 additions and 1 deletions

View File

@ -152,7 +152,7 @@ class Tag < ActiveRecord::Base
end
def full_url
"#{Discourse.base_url}/tag/#{self.name}"
"#{Discourse.base_url}/tag/#{UrlHelper.encode_component(self.name)}"
end
def index_search

View File

@ -202,6 +202,14 @@ describe Tag do
end
end
context "full_url" do
let(:tag) { Fabricate(:tag, name: "🚀") }
it "percent encodes emojis" do
expect(tag.full_url).to eq("http://test.localhost/tag/%F0%9F%9A%80")
end
end
context "synonyms" do
let(:synonym) { Fabricate(:tag, target_tag: tag) }