Skip to content

Commit 3f1992b

Browse files
committed
Preserve encoded commas in feature keys
1 parent bbdb2fd commit 3f1992b

2 files changed

Lines changed: 20 additions & 2 deletions

File tree

lib/flipper/api/v1/actions/features.rb

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,15 @@ def requested_feature_names
5252
return keys.map(&:to_s) if keys.is_a?(Array)
5353

5454
raw_keys = raw_query_values("keys")
55-
return decoded_feature_names if raw_keys.empty? || raw_keys.none? { |key| key.include?(',') }
55+
return decoded_feature_names if raw_keys.empty?
5656

5757
raw_keys.flat_map do |keys|
58-
keys.split(',').map { |key| Rack::Utils.unescape(key) }
58+
if keys.include?(',')
59+
keys.split(',').map { |key| Rack::Utils.unescape(key) }
60+
else
61+
decoded_keys = Rack::Utils.unescape(keys)
62+
feature_exists?(decoded_keys) ? decoded_keys : decoded_keys.split(',')
63+
end
5964
end
6065
end
6166

spec/flipper/api/v1/actions/features_spec.rb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,19 @@
111111
end
112112
end
113113

114+
context 'with a single encoded key containing a comma' do
115+
before do
116+
flipper["audit,log"].enable
117+
get '/features?keys=audit%2Clog'
118+
end
119+
120+
it 'treats the escaped comma as part of the feature key' do
121+
expect(last_response.status).to eq(200)
122+
keys = json_response.fetch('features').map { |feature| feature.fetch('key') }
123+
expect(keys).to eq(["audit,log"])
124+
end
125+
end
126+
114127
context 'with keys that are not existing features' do
115128
before do
116129
flipper[:search].disable

0 commit comments

Comments
 (0)