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

BugFixed: prevent toLowerCase crash the App. #2993

Closed
wants to merge 4 commits into from

Conversation

alvaropaco
Copy link

I caught this bug in development. When a user accidentaly ran a non string parameter to get on request, the App crashes.
I fixed this.

@dougwilson
Copy link
Contributor

Thanks! A few thoughts: I would rather change this to throw a TypeError when not given a string instead of skipping lower casing, or perhaps coerce to argument to a string. Would like thoughts on this from other members.

Also, please add a test that tests this condition, which is a prereq to accept the pull request.

@alvaropaco
Copy link
Author

All right @dougwilson , i'll do that. So, in my opinion is better throw a TypeError.

@dougwilson
Copy link
Contributor

Sounds good, @ScalaSoft, please ping me once you've updated the pull request :)

@alvaropaco
Copy link
Author

@dougwilson I made the necessary changes. Please check.


app.use(function(req, res){
var name = ['something'];
assert.throws(typeThrowError(name), TypeError, "Error thrown");
Copy link
Contributor

Choose a reason for hiding this comment

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

This test is just testing the function typeThrowError in this file, and is not actually testing the new if statement you added in lib/request.js. This is the reason your pull request is in a failure state, because you haven't actually tested your change yet :) To test your change, you'd want to do something like req.header(42) and test that it threw.


// If name wasn't a string, it will crash
if(typeof name !== 'string') {
return new TypeError('Parameter "name" needs to be a String but got a ' + (typeof name));
Copy link
Contributor

Choose a reason for hiding this comment

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

The error should be thrown, not returned. If you are going to go along the pattern of "but go a..." I would suggest using the type detection routing from the rest of the case base, which better handles all the various things that simply return object, like for example, null.

@dougwilson dougwilson added this to the 4.14 milestone Jun 1, 2016
@dougwilson dougwilson mentioned this pull request Jun 1, 2016
16 tasks
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.

None yet

2 participants