From 7afcb664fb2165814efcd3f652d0e06941c6fba3 Mon Sep 17 00:00:00 2001 From: Renato Atilio Date: Thu, 30 Mar 2023 09:35:06 -0300 Subject: [PATCH] FIX: pretty-text shims - getURL's baseUri (#20822) --- lib/pretty_text/shims.js | 2 +- spec/lib/pretty_text_spec.rb | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/lib/pretty_text/shims.js b/lib/pretty_text/shims.js index 1c54183c922..793a3992eb5 100644 --- a/lib/pretty_text/shims.js +++ b/lib/pretty_text/shims.js @@ -78,7 +78,7 @@ function __getURLNoCDN(url) { return url; } - if (url.includes(__paths.baseUri)) { + if (url.startsWith(`${__paths.baseUri}/`) || url === __paths.baseUri) { return url; } if (url[0] !== "/") { diff --git a/spec/lib/pretty_text_spec.rb b/spec/lib/pretty_text_spec.rb index cf53fc17f72..30fb439ffa7 100644 --- a/spec/lib/pretty_text_spec.rb +++ b/spec/lib/pretty_text_spec.rb @@ -1534,6 +1534,27 @@ RSpec.describe PrettyText do it "replaces Emoji from Unicode 14.0" do expect(PrettyText.cook("🫣")).to match(/\:face_with_peeking_eye\:/) end + + context "with subfolder" do + it "prepends the subfolder path to the emoji url" do + set_subfolder "/forum" + + expected = "src=\"/forum/images/emoji/twitter/grinning.png?v=#{Emoji::EMOJI_VERSION}\"" + + expect(PrettyText.cook("😀")).to include(expected) + expect(PrettyText.cook(":grinning:")).to include(expected) + end + + it "prepends the subfolder path even if it is part of the emoji url" do + set_subfolder "/info" + + expected = + "src=\"/info/images/emoji/twitter/information_source.png?v=#{Emoji::EMOJI_VERSION}\"" + + expect(PrettyText.cook("ℹ️")).to include(expected) + expect(PrettyText.cook(":information_source:")).to include(expected) + end + end end describe "custom emoji" do