-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Validate hostname in uri #2846
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
base: master
Are you sure you want to change the base?
Validate hostname in uri #2846
Changes from 3 commits
4234132
b23ce51
f1f0322
25777d5
3cb8376
9c83bd5
a90120b
4d29bab
2e754a3
06483be
4053a1b
5c2a000
45c32ee
1a9f9a5
53de422
d74362c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -639,7 +639,7 @@ module.exports = Any.extend({ | |||||
| Common.assertOptions(options, ['allowRelative', 'allowQuerySquareBrackets', 'domain', 'relativeOnly', 'scheme']); | ||||||
|
|
||||||
| if (options.domain) { | ||||||
| Common.assertOptions(options.domain, ['allowFullyQualified', 'allowUnicode', 'maxDomainSegments', 'minDomainSegments', 'tlds']); | ||||||
| Common.assertOptions(options.domain, ['allowFullyQualified', 'allowUnicode', 'maxDomainSegments', 'minDomainSegments', 'tlds', 'hostname']); | ||||||
| } | ||||||
|
|
||||||
| const { regex, scheme } = Uri.regex(options); | ||||||
|
|
@@ -662,6 +662,13 @@ module.exports = Any.extend({ | |||||
| return helpers.error('string.domain', { value: matched }); | ||||||
| } | ||||||
|
|
||||||
| if(options?.domain?.hostname){ | ||||||
|
||||||
| const { hostname } = options.domain; | ||||||
| if(hostname !== matched){ | ||||||
| return helpers.error('string.uri.hostname', { value: matched }); | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
| return value; | ||||||
| } | ||||||
|
|
||||||
|
|
@@ -721,6 +728,7 @@ module.exports = Any.extend({ | |||||
| 'string.pattern.invert.name': '{{#label}} with value {:[.]} matches the inverted {{#name}} pattern', | ||||||
| 'string.trim': '{{#label}} must not have leading or trailing whitespace', | ||||||
| 'string.uri': '{{#label}} must be a valid uri', | ||||||
| 'string.uri.hostname': '{{#label}} is not from given hostname', | ||||||
|
||||||
| 'string.uri.hostname': '{{#label}} is not from given hostname', | |
| 'string.uri.hostname': '{{#label}} does not match {{#expected}} hostname' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I made some changes to make the error more useful, following the example.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If this is going to be part of
domain, you should probably exclude it from the call toisValidto avoid any possible side-effect from an evolution of that module.