FIX: Incorrect/missing extension in short_url fails to map to upload.
`Hash#invert` causes us to lose keys if the hash contains similar values.
This commit is contained in:
parent
3134dd4763
commit
f3aef2cc83
|
@ -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
|
||||
|
|
|
@ -1228,6 +1228,8 @@ HTML
|
|||
|
||||
- test
|
||||
- ![upload](#{upload.short_url})
|
||||
|
||||
![upload](#{upload.short_url.gsub!(".png", "")})
|
||||
RAW
|
||||
|
||||
cooked = <<~HTML
|
||||
|
@ -1243,6 +1245,7 @@ HTML
|
|||
</ul>
|
||||
</li>
|
||||
</ul>
|
||||
<p><img src="#{upload.url}" alt="upload"></p>
|
||||
HTML
|
||||
|
||||
expect(PrettyText.cook(raw)).to eq(cooked.strip)
|
||||
|
|
Loading…
Reference in New Issue