From: Thibaut Girka Date: Fri, 24 Jan 2020 13:37:06 +0000 (+0100) Subject: Merge branch 'master' into glitch-soc/merge-upstream X-Git-Url: https://git.xn--scling-oua.cat.family/?a=commitdiff_plain;h=9adeaf2bfc1c16ca70e611b5288886b21414217b;p=mastodon.git Merge branch 'master' into glitch-soc/merge-upstream Conflicts: - `app/controllers/statuses_controller.rb`: Minor conflict due to theming system --- 9adeaf2bfc1c16ca70e611b5288886b21414217b diff --cc app/controllers/statuses_controller.rb index 1b00d38c9,4fa128303..588063d01 --- a/app/controllers/statuses_controller.rb +++ b/app/controllers/statuses_controller.rb @@@ -48,8 -46,7 +48,8 @@@ class StatusesController < ApplicationC end def embed + use_pack 'embed' - raise ActiveRecord::RecordNotFound if @status.hidden? + return not_found if @status.hidden? expires_in 180, public: true response.headers['X-Frame-Options'] = 'ALLOWALL' diff --cc app/lib/formatter.rb index 36cdae9f7,2c5674869..f1a751f84 --- a/app/lib/formatter.rb +++ b/app/lib/formatter.rb @@@ -308,34 -245,11 +308,34 @@@ class Formatte end standard = Extractor.extract_entities_with_indices(text, options) - xmpp = Extractor.extract_xmpp_uris_with_indices(text, options) + extra = Extractor.extract_extra_uris_with_indices(text, options) - Extractor.remove_overlapping_entities(special + standard + xmpp) + Extractor.remove_overlapping_entities(special + standard + extra) end + def html_friendly_extractor(html, options = {}) + gaps = [] + total_offset = 0 + + escaped = html.gsub(/<[^>]*>|&#[0-9]+;/) do |match| + total_offset += match.length - 1 + end_offset = Regexp.last_match.end(0) + gaps << [end_offset - total_offset, total_offset] + "\u200b" + end + + entities = Extractor.extract_hashtags_with_indices(escaped, :check_url_overlap => false) + + Extractor.extract_mentions_or_lists_with_indices(escaped) + Extractor.remove_overlapping_entities(entities).map do |extract| + pos = extract[:indices].first + offset_idx = gaps.rindex { |gap| gap.first <= pos } + offset = offset_idx.nil? ? 0 : gaps[offset_idx].last + next extract.merge( + :indices => [extract[:indices].first + offset, extract[:indices].last + offset] + ) + end + end + def link_to_url(entity, options = {}) url = Addressable::URI.parse(entity[:url]) html_attrs = { target: '_blank', rel: 'nofollow noopener noreferrer' }