diff --git a/lib/pretty_text/helpers.rb b/lib/pretty_text/helpers.rb index b8376a731cf..09d7b1a31b9 100644 --- a/lib/pretty_text/helpers.rb +++ b/lib/pretty_text/helpers.rb @@ -63,13 +63,18 @@ module PrettyText end if map.length > 0 - reverse_map = map.invert + reverse_map = {} + + map.each do |key, value| + reverse_map[value] ||= [] + reverse_map[value] << key + end Upload.where(sha1: map.values).pluck(:sha1, :url).each do |row| sha1, url = row - if short_url = reverse_map[sha1] - result[short_url] = url + if short_urls = reverse_map[sha1] + short_urls.each { |short_url| result[short_url] = url } end end end diff --git a/spec/components/pretty_text_spec.rb b/spec/components/pretty_text_spec.rb index fe0a6686a01..d115a69bfff 100644 --- a/spec/components/pretty_text_spec.rb +++ b/spec/components/pretty_text_spec.rb @@ -1228,6 +1228,8 @@ HTML - test -  + + }) RAW cooked = <<~HTML @@ -1243,6 +1245,7 @@ HTML +