Skip to content

Commit f42841d

Browse files
authored
Merge pull request #960 from flippercloud/link-fix
Allow links in descriptions
2 parents 142ee74 + f912695 commit f42841d

File tree

3 files changed

+28
-1
lines changed

3 files changed

+28
-1
lines changed

lib/flipper/ui/action.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,14 @@
77

88
module Flipper
99
module UI
10+
# Sanitize config for descriptions in list view. Removes anchor tags to
11+
# avoid nested links (the feature row is wrapped in an <a> tag).
12+
# See: https://github.com/flippercloud/flipper/issues/939
13+
SANITIZE_LIST = Sanitize::Config.merge(
14+
Sanitize::Config::BASIC,
15+
elements: Sanitize::Config::BASIC[:elements] - ['a']
16+
)
17+
1018
class Action
1119
module FeatureNameFromRoute
1220
def feature_name

lib/flipper/ui/views/features.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
<div class="text-truncate" style="font-weight: 500"><%= feature.key %></div>
4646
<% if Flipper::UI.configuration.show_feature_description_in_list? && Flipper::UI::Util.present?(feature.description) %>
4747
<div class="text-muted fw-light" style="line-height: 1.4; white-space: initial; padding: 8px 0">
48-
<%== Sanitize.fragment(feature.description, Sanitize::Config::BASIC) %>
48+
<%== Sanitize.fragment(feature.description, Flipper::UI::SANITIZE_LIST) %>
4949
</div>
5050
<% end %>
5151
<div class="text-muted text-truncate">

spec/flipper/ui/actions/features_spec.rb

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,25 @@
8888
expect(last_response.body).not_to include('<a class="btn btn-primary btn-sm" href="/features/new">Add Feature</a>')
8989
end
9090
end
91+
92+
context 'when descriptions have links' do
93+
before do
94+
Flipper::UI.configuration.show_feature_description_in_list = true
95+
Flipper::UI.configuration.descriptions_source = lambda { |_keys|
96+
{ 'test_feature' => 'Check <a href="https://example.com">this link</a> for more info' }
97+
}
98+
99+
flipper[:test_feature].enable
100+
end
101+
102+
it 'strips anchor tags from descriptions to avoid nested links' do
103+
get '/features'
104+
105+
expect(last_response.status).to eq(200)
106+
expect(last_response.body).to include('Check this link for more info')
107+
expect(last_response.body).not_to include('<a href="https://example.com">this link</a>')
108+
end
109+
end
91110
end
92111

93112
describe 'POST /features' do

0 commit comments

Comments
 (0)