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

Fix matchStringOrRegexp TypeError #998

Merged
merged 2 commits into from
Oct 20, 2017
Merged

Fix matchStringOrRegexp TypeError #998

merged 2 commits into from
Oct 20, 2017

Conversation

serahhh
Copy link
Contributor

@serahhh serahhh commented Oct 19, 2017

Fixes TypeError: Cannot read property 'match' of undefined when pattern is a regex and target is undefined.

@coveralls
Copy link

coveralls commented Oct 19, 2017

Coverage Status

Coverage remained the same at 92.666% when pulling 26d29b6 on serahhh:master into ea2fe9f on node-nock:master.

Copy link
Member

@paulmelnikow paulmelnikow left a comment

Choose a reason for hiding this comment

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

Hi! Thanks for this.

lib/common.js Outdated
@@ -320,7 +320,7 @@ function percentEncode(str) {
}

function matchStringOrRegexp(target, pattern) {
var str = !_.isUndefined(target) && target.toString ? target.toString() : target;
var str = !_.isUndefined(target) ? (target.toString ? target.toString() : target) : '';
Copy link
Member

Choose a reason for hiding this comment

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

It's a bit difficult to understand this double conditional expression. Would it be clearer as an if () ... else if () ... else?

@serahhh
Copy link
Contributor Author

serahhh commented Oct 20, 2017

Hi, I have simplified the logic. I'm assuming target should always be string-like, otherwise use an empty string as a fallback.

@coveralls
Copy link

coveralls commented Oct 20, 2017

Coverage Status

Coverage increased (+0.005%) to 92.671% when pulling a626488 on serahhh:master into ea2fe9f on node-nock:master.

@paulmelnikow paulmelnikow merged commit 62e7566 into nock:master Oct 20, 2017
@paulmelnikow
Copy link
Member

Thanks!

@lock
Copy link

lock bot commented Sep 13, 2018

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue and add a reference to this one if it’s related. Thank you!

@lock lock bot locked as resolved and limited conversation to collaborators Sep 13, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants