0
0
Fork 0
mirror of https://github.com/discourse/discourse.git synced 2026-08-09 21:45:25 +08:00
discourse/plugins/discourse-calendar/spec/system/composer/event_location_spec.rb
Régis Hanol f91d7a9976
FIX: Cook event location and description as inline markdown (#41994)
Previously, a markdown link in an event's location rendered correctly in
email notifications but showed as raw `[text](url)` markup on the event
card. Every surface (card, email, topic excerpt) re-implemented its own
rendering of the same fields, and `extract_events` HTML-escaped the
stored location one level further on every edit.

This change cooks `location` and `description` once, server side, with a
restricted inline pipeline (links and emoji only, so onebox embeds
cannot return), and every surface renders through that shared cook — the
card via new `location_html`/`description_html` serializer attributes.
It stops escaping the stored location, with a migration healing existing
rows, and moves the composer's `[event]` parsing onto core's
`parseBBCodeTag` so quoted attribute values containing `]` survive
round-trips.

Ref - t/188447
2026-07-28 18:59:23 +02:00

76 lines
2.4 KiB
Ruby
Vendored

# frozen_string_literal: true
describe "Composer - Event location" do
fab!(:admin)
let(:composer) { PageObjects::Components::Composer.new }
let(:markdown_location) { "[RSVP](https://zoom.example.com/j/123)" }
let(:event_markup) { <<~MD.strip }
[event start="2026-08-01 18:00" status="public" timezone="UTC" location="#{markdown_location}"]
[/event]
MD
before do
SiteSetting.calendar_enabled = true
SiteSetting.discourse_post_event_enabled = true
sign_in(admin)
end
it "renders a markdown-link location on the posted card and keeps it stable when edited in the markdown composer" do
visit("/new-topic")
composer.fill_title("Event with a markdown location")
composer.fill_content(event_markup)
expect(page.find(".composer-event__location-input").value).to eq(markdown_location)
composer.create
expect(page).to have_css(
".event-location a[href='https://zoom.example.com/j/123']",
text: "RSVP",
)
topic = Topic.find_by(title: "Event with a markdown location")
find("#post_1 .show-more-actions").click
find("#post_1 .edit").click
expect(page.find(".composer-event__location-input").value).to eq(markdown_location)
composer.create
expect(page).to have_css(".event-location a", text: "RSVP")
expect(DiscoursePostEvent::Event.find(topic.first_post.id).location).to eq(markdown_location)
end
it "shows the link affordance for scheme-less urls, matching what the card links" do
visit("/new-topic")
composer.fill_title("Event with a scheme-less location")
composer.fill_content(<<~MD.strip)
[event start="2026-08-01 18:00" status="public" timezone="UTC" location="zoom.us/j/123"]
[/event]
MD
expect(page).to have_css(".composer-event__location-external-link[href='http://zoom.us/j/123']")
composer.create
expect(page).to have_css(".event-location a", text: "zoom.us/j/123")
end
context "with the rich editor" do
include_context "with prosemirror editor"
it "round-trips a markdown-link location through the event node" do
open_composer
composer.toggle_rich_editor
composer.fill_content(event_markup)
composer.toggle_rich_editor
expect(rich.find(".composer-event__location-input").value).to eq(markdown_location)
composer.toggle_rich_editor
expect(composer).to have_value(%r{location="\[RSVP\]\(https://zoom\.example\.com/j/123\)"})
end
end
end