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

Raise routing errors for invalid or empty page ids #178

Merged
merged 1 commit into from Feb 19, 2015

Conversation

prydonius
Copy link

Visiting page_ids made entirely up of invalid characters gets sanitised into an empty string, so it looks for a template called "pages/". This raises a missing template error (because it doesn't match the regex checking that it isn't a missing partial).

This commit adds a check to see if the page_id is empty after sanitisation, and raises and error if it is -- which is caught and turned into a routing error.

@@ -31,7 +31,13 @@ def clean_path
end

def clean_id
@page_id.tr("^#{VALID_CHARACTERS}", '')
@page_id.tr("^#{VALID_CHARACTERS}", '').tap do |id|

Choose a reason for hiding this comment

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

Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.

@dgalarza
Copy link
Contributor

Thanks for the pr @prydonius. Sorry for the delay. Would you mind updating to handle the style issues Hound commented on? Thanks!

before { get :show, :id => 'exists' }
context "using default configuration" do
describe "on GET to /pages/exists" do
before { get :show, :id => "exists" }

Choose a reason for hiding this comment

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

Use the new Ruby 1.9 hash syntax.

@prydonius
Copy link
Author

No worries, @dgalarza! Rebased and fixed the style issues.

@@ -31,7 +31,13 @@ def clean_path
end

def clean_id
@page_id.tr("^#{VALID_CHARACTERS}", '')
@page_id.tr("^#{VALID_CHARACTERS}", "").tap do |id|
unless id.length > 0
Copy link
Contributor

Choose a reason for hiding this comment

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

How about if id.blank?

@dgalarza
Copy link
Contributor

dgalarza commented Feb 2, 2015

Thanks for the update @prydonius. Do you feel comfortable rebasing and squashing to prep for a merge.

@prydonius
Copy link
Author

@dgalarza is this ready to be merged in now?

dgalarza added a commit that referenced this pull request Feb 19, 2015
Raise routing errors for invalid or empty page ids
@dgalarza dgalarza merged commit 2da3faa into thoughtbot:master Feb 19, 2015
@dgalarza
Copy link
Contributor

👍 thanks for the contribution @prydonius

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.

None yet

3 participants