Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Strip whitespace out of feature/actor/group values posted by UI #205

Merged
merged 2 commits into from
Nov 25, 2016
Merged

Strip whitespace out of feature/actor/group values posted by UI #205

merged 2 commits into from
Nov 25, 2016

Conversation

KevinBongart
Copy link
Contributor

Fix #204

By investigating the initial issue, I was able to identify several areas impacted by it.

  1. Using the UI to create two features with similar names but different whitespace:
> $flipper.features
=> #<Set: {#<Flipper::Feature:70136261075520 name="   whitespace", state=:conditional, enabled_gate_names=[:actor], adapter=:memoizable>,
 #<Flipper::Feature:70136261217520 name="   whitespace   ", state=:conditional, enabled_gate_names=[:actor], adapter=:memoizable>}>
  1. Still via the UI, adding an actor to the second one seemed to have actually added it to the first one.

  2. Both links in the UI leads to the same feature:

screen shot 2016-11-23 at 11 01 10 am

  1. Copy-pasting actor values from one Flipper UI to another adds some whitespace which ends up in Flipper:
> $flipper["   whitespace"].actors_value
=> #<Set: {"    [email protected]\t"}>

This PR fixes all of these issues above by applying String#strip to the params send from the front-end to the back-end of Flipper UI.

cc @jnunemaker & @AlexWheeler for review/feedback, and @susanblueapron for finding the bug in the first place

@@ -24,7 +24,7 @@ def get
def post
feature_name = Rack::Utils.unescape(request.path.split('/')[-2])
feature = flipper[feature_name.to_sym]
value = params["value"]
value = params["value"].strip

if Util.blank?(value)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks like the code expects a possible nil value here, which means that your change on line 27 will raise an undefined method for nil nilclass

maybe strip inside the if block?

@@ -34,7 +34,7 @@ def post
halt view_response(:feature_creation_disabled)
end

value = params["value"]
value = params["value"].strip
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as above

before do
flipper[:search].enable_actor Flipper::UI::Actor.new("User:6")
post "features/search/actors",
{"value" => "User:6", "operation" => "disable", "authenticity_token" => token},
{"value" => value, "operation" => "disable", "authenticity_token" => token},
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe add a test where you don't pass a value? seems like that's missing here

@KevinBongart
Copy link
Contributor Author

KevinBongart commented Nov 23, 2016

@midu Added more tests related to empty values (not exactly the same as a param hash missing the "value" key but close enough). Not sure what's best between:

  1. value = params["value"].to_s.strip
  2. value = params["value"]&.strip (only compatible with Ruby 2.3+ I believe?)
  3. value = params["value"] && params["value"].strip

I do wanna make sure the value (nil, empty or present) is converted to a string and cleaned up before we test for its validity so that the UI helps the user as much as possible

@jnunemaker
Copy link
Collaborator

My preference is to_s.strip. It works with older versions of ruby and flipper doesn't care about nil uniquely since nil/blank are treated the same.

Copy link
Collaborator

@jnunemaker jnunemaker left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great. Thanks!

@jnunemaker jnunemaker merged commit a27cf80 into flippercloud:master Nov 25, 2016
@KevinBongart KevinBongart deleted the remove_whitespace_from_values_posted_from_ui branch November 26, 2016 08:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Whitespace in actors_value but not in actor's flipper_id
3 participants