Skip to content
This repository has been archived by the owner on Nov 1, 2017. It is now read-only.

Allow regexp for a allowed_request_origins array #130

Merged
merged 2 commits into from
Dec 13, 2015

Conversation

adamliesko
Copy link
Contributor

Adding the feature of additional regexp check for allowed_origin_requestsinstead of only strict equal comparation.

Fixes #130

@adamliesko adamliesko changed the title Allow regexp for a allowed_request_origins array #129 Allow regexp for a allowed_request_origins array Dec 5, 2015
@@ -180,6 +180,11 @@ def allow_request_origin?
end
end

def allowed_origins_match? origin
allowed_origins = Array(server.config.allowed_request_origins)
allowed_origins.any? { |allowed_origin| allowed_origin.is_a?(Regexp) ? allowed_origin =~ origin : allowed_origin == origin }
Copy link
Contributor

Choose a reason for hiding this comment

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

You could use the === operator to match both strings and regexes, so the class check wouldn't be required.

allowed_origins.any? { |allowed_origin| allowed_origin === origin }

Copy link
Member

Choose a reason for hiding this comment

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

Actually, given this, we don't need the extra method. We can just inline this === check like we had the original include call.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure, that makes sense. Thanks.

Copy link
Contributor

Choose a reason for hiding this comment

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

@adamliesko I don't think this method is used anymore and can be removed.

@dhh
Copy link
Member

dhh commented Dec 11, 2015

@adamliesko Do you want to wrap up these changes? Then we can merge.

@adamliesko
Copy link
Contributor Author

@dhh I have updated the README.md and rebased the branch anything else left to do?

dhh added a commit that referenced this pull request Dec 13, 2015
Allow regexp for a allowed_request_origins array
@dhh dhh merged commit 5fec4b9 into rails:master Dec 13, 2015
@dhh
Copy link
Member

dhh commented Dec 13, 2015

👏

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
3 participants