Skip to content

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

Merged
paulmelnikow merged 6 commits intonock:masterfrom
TLPcoder:empty-string-1730
Oct 22, 2019
Merged

feat: Throw errors for URL paths without leading slashes, which will never match#1744
paulmelnikow merged 6 commits intonock:masterfrom
TLPcoder:empty-string-1730

Conversation

@TLPcoder
Copy link
Copy Markdown
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
Copy Markdown
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.

@TLPcoder
Copy link
Copy Markdown
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.

@paulmelnikow
Copy link
Copy Markdown
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().

@paulmelnikow
Copy link
Copy Markdown
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
Copy Markdown
Member

Congrats on a first PR to Nock! 🎉 🚀

@nockbot
Copy link
Copy Markdown
Collaborator

nockbot commented Oct 22, 2019

🎉 This PR is included in version 11.5.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

juninmd pushed a commit to juninmd/nock that referenced this pull request Mar 21, 2026
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