about summary refs log tree commit diff
path: root/app
diff options
context:
space:
mode:
Diffstat (limited to 'app')
-rw-r--r--app/controllers/api/web/embeds_controller.rb16
-rw-r--r--app/lib/formatter.rb3
2 files changed, 14 insertions, 5 deletions
diff --git a/app/controllers/api/web/embeds_controller.rb b/app/controllers/api/web/embeds_controller.rb
index 3e7919184..c05af4456 100644
--- a/app/controllers/api/web/embeds_controller.rb
+++ b/app/controllers/api/web/embeds_controller.rb
@@ -7,15 +7,21 @@ class Api::Web::EmbedsController < Api::Web::BaseController
 
   def create
     status = StatusFinder.new(params[:url]).status
+
+    return not_found unless status.distributable?
+
     render json: status, serializer: OEmbedSerializer, width: 400, monsterfork_api: monsterfork_api
   rescue ActiveRecord::RecordNotFound
     oembed = FetchOEmbedService.new.call(params[:url])
-    oembed[:html] = Formatter.instance.sanitize(oembed[:html], Sanitize::Config::MASTODON_OEMBED) if oembed[:html].present?
 
-    if oembed
-      render json: oembed
-    else
-      render json: {}, status: :not_found
+    return not_found if oembed.nil?
+
+    begin
+      oembed[:html] = Formatter.instance.sanitize(oembed[:html], Sanitize::Config::MASTODON_OEMBED)
+    rescue ArgumentError
+      return not_found
     end
+
+    render json: oembed
   end
 end
diff --git a/app/lib/formatter.rb b/app/lib/formatter.rb
index b81ef8668..77b3ac97e 100644
--- a/app/lib/formatter.rb
+++ b/app/lib/formatter.rb
@@ -248,6 +248,7 @@ class Formatter
     html.html_safe # rubocop:disable Rails/OutputSafety
   end
 
+<<<<<<< HEAD
   def format_screenreader(html)
     html.gsub(/\ufdd3(.*)\ufdd4/m, '<span aria-hidden="true">\1</span>')
   end
@@ -278,6 +279,8 @@ class Formatter
     html.gsub!("\r\n", "\n")
     html.gsub!("\n\r", "\n")
     html.gsub("\r", "\n")
+  rescue ArgumentError
+    ''
   end
 
   def plaintext(status)