FIX: Do not extract dates from quotes and Oneboxes (#8754)
Post.local_dates used to contain dates from quotes and Oneboxes.
This commit is contained in:
parent
4e6ca5610c
commit
03143d9449
|
@ -26,19 +26,21 @@ after_initialize do
|
||||||
register_post_custom_field_type(DiscourseLocalDates::POST_CUSTOM_FIELD, :json)
|
register_post_custom_field_type(DiscourseLocalDates::POST_CUSTOM_FIELD, :json)
|
||||||
|
|
||||||
on(:before_post_process_cooked) do |doc, post|
|
on(:before_post_process_cooked) do |doc, post|
|
||||||
dates =
|
dates = []
|
||||||
doc.css('span.discourse-local-date').map do |cooked_date|
|
|
||||||
date = {}
|
doc.css('span.discourse-local-date').map do |cooked_date|
|
||||||
cooked_date.attributes.values.each do |attribute|
|
next if cooked_date.ancestors("aside").length > 0
|
||||||
data_name = attribute.name&.gsub('data-', '')
|
date = {}
|
||||||
if data_name && %w[date time timezone recurring].include?(data_name)
|
cooked_date.attributes.values.each do |attribute|
|
||||||
unless attribute.value == 'undefined'
|
data_name = attribute.name&.gsub('data-', '')
|
||||||
date[data_name] = CGI.escapeHTML(attribute.value || '')
|
if data_name && %w[date time timezone recurring].include?(data_name)
|
||||||
end
|
unless attribute.value == 'undefined'
|
||||||
|
date[data_name] = CGI.escapeHTML(attribute.value || '')
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
date
|
|
||||||
end
|
end
|
||||||
|
dates << date
|
||||||
|
end
|
||||||
|
|
||||||
if dates.present?
|
if dates.present?
|
||||||
post.custom_fields[DiscourseLocalDates::POST_CUSTOM_FIELD] = dates
|
post.custom_fields[DiscourseLocalDates::POST_CUSTOM_FIELD] = dates
|
||||||
|
|
|
@ -26,6 +26,29 @@ describe Post do
|
||||||
|
|
||||||
expect(post.local_dates).to eq([])
|
expect(post.local_dates).to eq([])
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "should not contain dates from quotes" do
|
||||||
|
post = Fabricate(:post, raw: <<~SQL)
|
||||||
|
[quote]
|
||||||
|
[date=2018-09-17 time=01:39:00 format="LLL" timezone="Europe/Paris" timezones="Europe/Paris|America/Los_Angeles"]
|
||||||
|
[/quote]
|
||||||
|
SQL
|
||||||
|
CookedPostProcessor.new(post).post_process
|
||||||
|
|
||||||
|
expect(post.local_dates.count).to eq(0)
|
||||||
|
end
|
||||||
|
|
||||||
|
it "should not contain dates from examples" do
|
||||||
|
Oneboxer.stubs(:cached_onebox).with('https://example.com').returns(<<-HTML)
|
||||||
|
<aside class="onebox githubcommit">
|
||||||
|
<span class="discourse-local-date" data-format="ll" data-date="2020-01-20" data-time="15:06:58" data-timezone="UTC">03:06PM - 20 Jan 20 UTC</span>
|
||||||
|
</aside>
|
||||||
|
HTML
|
||||||
|
post = Fabricate(:post, raw: "https://example.com")
|
||||||
|
CookedPostProcessor.new(post).post_process
|
||||||
|
|
||||||
|
expect(post.local_dates.count).to eq(0)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue