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

Support Slashes in Feature Names in UI/API #362

Merged
merged 12 commits into from
Jul 31, 2018
Merged

Support Slashes in Feature Names in UI/API #362

merged 12 commits into from
Jul 31, 2018

Conversation

jnunemaker
Copy link
Collaborator

@jnunemaker jnunemaker commented Jun 3, 2018

As brought up in #357, flipper UI (and API) do not handle slashes in feature names. This fixes that. I had to redo routing stuff, but it should all work the same.

I considered adding a note that slashes aren't supported, but it wasn't too bad to add support so why not. There is some duplication in finding the feature name, but I didn't feel like there was enough to warrant any abstracting just yet. We'll see if this churns at all and would benefit from that down the road.

fixes #357

refs #357

This is a tricky one. The issue is that I was assuming no one would use slashes. Using a slash completely broke all the routing. I changed the routing to be a block so it is more flexible. Now it is possible to route based on anything in request.

The API will likely need the same work.
@jnunemaker jnunemaker self-assigned this Jun 3, 2018
@jnunemaker jnunemaker changed the title Slash names Support Slashes in Feature Names in UI/API Jun 3, 2018
it 'renders add new actor form' do
form = '<form action="/features/a/b/actors" method="post" class="form-inline">'
expect(last_response.body).to include(form)
end
Copy link
Collaborator

Choose a reason for hiding this comment

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

👍

Copy link
Collaborator

@AlexWheeler AlexWheeler left a comment

Choose a reason for hiding this comment

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

This looks great! Curious what the reason for removing self.regex and adding match which takes a block? Is that to make it more flexible? because this PR should work with just updating the regexes to accept the (.*) capture groups right?

@feature_name ||= Rack::Utils.unescape(path_parts[-2])
@feature_name ||= begin
match = request.path_info.match(REGEX)
match ? match[1] : nil
Copy link
Collaborator

Choose a reason for hiding this comment

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

super minor suggestion these regexes could use named capture groups that might read slightly better, but this also works great as is

REGEX = %r{\A/features/(?<feature_name>.*)/actors/?\Z}

def feature_name
  if match = request.path_info.match(REGEX)
    match[:feature_name]
  end
end

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I almost went for a capture group, but this took so much longer than I was planning I lost steam. I think it is worth updating to use them so I'll spin back around on it soon.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Updated in f61bbe9

@jnunemaker
Copy link
Collaborator Author

Curious what the reason for removing self.regex and adding match which takes a block? Is that to make it more flexible?

There was definitely a reason in the beginning that had to do with escaping/matching regex, but I wonder if at some point I worked around that and never went back. I'll look at swapping it out again and see how that works.

We just need to match the path info to a regex. We don't need the whole request.
@jnunemaker
Copy link
Collaborator Author

Moved back to single regex in 8fa06a5. Going to get rid of the constants too.

@jnunemaker
Copy link
Collaborator Author

Ok, waiting for CI but I think this is ready and I'm going to merge soon.

@jnunemaker jnunemaker merged commit d67db88 into master Jul 31, 2018
@jnunemaker jnunemaker deleted the slash-names branch July 31, 2018 18:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Flipper UI crashes if feature key contains a '/'
2 participants