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

feat: Throw errors for URL paths without leading slashes, which will never match #1744

Merged
merged 6 commits into from Oct 22, 2019
Merged

feat: Throw errors for URL paths without leading slashes, which will never match #1744

merged 6 commits into from Oct 22, 2019

Conversation

TLPcoder
Copy link
Contributor

@TLPcoder TLPcoder commented Oct 14, 2019

Added a check for filteringScope in the scope options as @paulmelnikow suggested. Also updated the two test which did not have the root path defined as this change will enforce this. To make the compatible with request like { hostname: 'example.test' } changed default value from { path = '' } to { path = '/' } in the interceptor class.

Fix #1730

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! Here are a few minor comments.

Another question is whether we should consider this a new feature (i.e. a better error message when passing a string that will match nothing) or if there is any legitimate use case where an empty string (or no string) is passed.

I guess people using filteringScope() might be passing a garbage string because that has always been allowed. So I think this needs to be considered a breaking change.

We've discussed setting a release schedule and batching up some of these breaking changes (so we only ship a breaking release every few months). Let's sort that out before merging this.

lib/interceptor.js Outdated Show resolved Hide resolved
package-lock.json Outdated Show resolved Hide resolved
lib/interceptor.js Show resolved Hide resolved
lib/interceptor.js Outdated Show resolved Hide resolved
@TLPcoder
Copy link
Contributor Author

To make this change the most backwards compatible I have added a check for the filteringScope option and have added a test in a newer commit with the changes you requested besides the startsWith change.

If the filteringScope option is populated the '/' check will not be honored. Because the path will never be used if filteringScope option is populated I think it makes sense to ignore the '/' check or require no argument at all.

I think the check for filteringScope should be include even if this commit is merged in the breaking change batch.

lib/interceptor.js Outdated Show resolved Hide resolved
tests/test_intercept.js Outdated Show resolved Hide resolved
@paulmelnikow
Copy link
Member

To make this change the most backwards compatible I have added a check for the filteringScope option and have added a test in a newer commit with the changes you requested besides the startsWith change.

If the filteringScope option is populated the '/' check will not be honored. Because the path will never be used if filteringScope option is populated I think it makes sense to ignore the '/' check or require no argument at all.

I think the check for filteringScope should be include even if this commit is merged in the breaking change batch.

I think this is a good solution, and means we can call this a new feature. Passing a string that never matches is almost certainly a programmer error, and Nock now throws an error when this happens.

If a programmer wants a conditional match and used a non-matching string as a workaround, this is better done using conditionally().

tests/test_intercept.js Outdated Show resolved Hide resolved
tests/test_intercept.js Outdated Show resolved Hide resolved
@paulmelnikow
Copy link
Member

This is looking good. I left a couple minor suggestions about test wording, though feel like this is otherwise good to merge as a new feature.

@paulmelnikow paulmelnikow changed the title fix #1730 enforces the standard of passing a valid path as the uri param to the interceptor class feat: Throw errors for URL paths without leading slashes which will never match Oct 21, 2019
@paulmelnikow paulmelnikow changed the title feat: Throw errors for URL paths without leading slashes which will never match feat: Throw errors for URL paths without leading slashes, which will never match Oct 22, 2019
@paulmelnikow paulmelnikow merged commit b7f9f13 into nock:master Oct 22, 2019
@paulmelnikow
Copy link
Member

Congrats on a first PR to Nock! 🎉 🚀

@nockbot
Copy link
Collaborator

nockbot commented Oct 22, 2019

🎉 This PR is included in version 11.5.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

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.

empty string vs "/"
3 participants