linkify all f-droid.org app/package links

fdroidserver#845
fdroidclient#1000
parent d4cbe192
Pipeline #217486405 passed with stage
in 2 minutes and 26 seconds
......@@ -160,11 +160,15 @@ module FDroid
self.format_description_to_html(string)
end
# Finds all "fdroid.app:" schemes in a particular string, and replaces with "/packages/".
# Finds all https://f-droid.org links that end with an Application ID, and
# replaces them with an HTML link.
# @param [string] string
# @return [string]
def self.replace_fdroid_app_links(string)
string.gsub /fdroid\.app:([\w._]*)/, '/packages/\1'
string.gsub(/fdroid\.app:([a-zA-Z0-9._]+)/,
'<a href="/packages/\1/"><tt>\1</tt></a>')
.gsub(/(https:\/\/f-droid\.org\/[^\s?#]+\/)((?:[a-zA-Z_]+(?:\d*[a-zA-Z_]*)*)(?:\.[a-zA-Z_]+(?:\d*[a-zA-Z_]*)*)*)\/?/,
'<a href="\1\2/"><tt>\2</tt></a>')
end
# Ensure newlines in descriptions are preserved (converted to "<br />" tags)
......
......@@ -58,6 +58,31 @@ here"
multi_line = App.format_description_to_html(text)
expect(multi_line).to eql("This<br />is<br />a<br /><br />multi-line<br /><br />string<br />here")
end
it 'Formats f-droid.org links in descriptions' do
text = "fdroid.app:com.linuxcounter.lico_update_003:"
multi_line = App.process_app_description(text)
expect(multi_line).to eql('<a href="/packages/com.linuxcounter.lico_update_003/"><tt>com.linuxcounter.lico_update_003</tt></a>:')
text = "pointing to https://f-droid.org/packages/com.banasiak.coinflip/:
This"
multi_line = App.process_app_description(text)
expect(multi_line).to eql('pointing to <a href="https://f-droid.org/packages/com.banasiak.coinflip/"><tt>com.banasiak.coinflip</tt></a>:<br /> This')
text = "https://f-droid.org/packages/SpeedoMeterApp.main.
(this"
multi_line = App.process_app_description(text)
expect(multi_line).to eql('<a href="https://f-droid.org/packages/SpeedoMeterApp.main/"><tt>SpeedoMeterApp.main</tt></a>.<br /> (this')
text = "works https://f-droid.org/packages/org.fitchfamily.android.wifi_backend_v2)
Do"
multi_line = App.process_app_description(text)
expect(multi_line).to eql('works <a href="https://f-droid.org/packages/org.fitchfamily.android.wifi_backend_v2/"><tt>org.fitchfamily.android.wifi_backend_v2</tt></a>)<br /> Do')
text = "forget https://f-droid.org/packages/org.microg.nlp"
multi_line = App.process_app_description(text)
expect(multi_line).to eql('forget <a href="https://f-droid.org/packages/org.microg.nlp/"><tt>org.microg.nlp</tt></a>')
end
end
RSpec.describe Permission do
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment