-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1034 from lamchakchan/string_allowRelativeOnly_su…
…pport added support for string.uri relativeOnly option
- Loading branch information
Showing
4 changed files
with
131 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1847,6 +1847,110 @@ describe('string', () => { | |
['/absolute', true] | ||
], done); | ||
}); | ||
|
||
it('validates relative only uri', (done) => { | ||
|
||
const schema = Joi.string().uri({ relativeOnly: true }); | ||
Helper.validate(schema, [ | ||
['foo://example.com:8042/over/there?name=ferret#nose', false, null, '"value" must be a valid relative uri'], | ||
['urn:example:animal:ferret:nose', false, null, '"value" must be a valid relative uri'], | ||
['ftp://ftp.is.co.za/rfc/rfc1808.txt', false, null, '"value" must be a valid relative uri'], | ||
['http://www.ietf.org/rfc/rfc2396.txt', false, null, '"value" must be a valid relative uri'], | ||
['ldap://[2001:db8::7]/c=GB?objectClass?one', false, null, '"value" must be a valid relative uri'], | ||
['mailto:[email protected]', false, null, '"value" must be a valid relative uri'], | ||
['news:comp.infosystems.www.servers.unix', false, null, '"value" must be a valid relative uri'], | ||
['tel:+1-816-555-1212', false, null, '"value" must be a valid relative uri'], | ||
['telnet://192.0.2.16:80/', false, null, '"value" must be a valid relative uri'], | ||
['urn:oasis:names:specification:docbook:dtd:xml:4.1.2', false, null, '"value" must be a valid relative uri'], | ||
['file:///example.txt', false, null, '"value" must be a valid relative uri'], | ||
['http://asdf:qw%20er@localhost:8000?asdf=12345&asda=fc%2F#bacon', false, null, '"value" must be a valid relative uri'], | ||
['http://asdf@localhost:8000', false, null, '"value" must be a valid relative uri'], | ||
['http://[v1.09azAZ-._~!$&\'()*+,;=:]', false, null, '"value" must be a valid relative uri'], | ||
['http://[a:b:c:d:e::1.2.3.4]', false, null, '"value" must be a valid relative uri'], | ||
['coap://[FEDC:BA98:7654:3210:FEDC:BA98:7654:3210]', false, null, '"value" must be a valid relative uri'], | ||
['http://[1080:0:0:0:8:800:200C:417A]', false, null, '"value" must be a valid relative uri'], | ||
['http://127.0.0.1:8000/foo?bar', false, null, '"value" must be a valid relative uri'], | ||
['http://asdf:qwer@localhost:8000', false, null, '"value" must be a valid relative uri'], | ||
['http://user:pass%3A@localhost:80', false, null, '"value" must be a valid relative uri'], | ||
['http://localhost:123', false, null, '"value" must be a valid relative uri'], | ||
['https://localhost:123', false, null, '"value" must be a valid relative uri'], | ||
['file:///whatever', false, null, '"value" must be a valid relative uri'], | ||
['mailto:[email protected]', false, null, '"value" must be a valid relative uri'], | ||
['ftp://www.example.com', false, null, '"value" must be a valid relative uri'], | ||
['javascript:alert(\'hello\');', false, null, '"value" must be a valid relative uri'], // eslint-disable-line no-script-url | ||
['xmpp:[email protected]', false, null, '"value" must be a valid relative uri'], | ||
['f://some.host/path', false, null, '"value" must be a valid relative uri'], | ||
['http://localhost:18/asdf', false, null, '"value" must be a valid relative uri'], | ||
['http://localhost:42/asdf?qwer=zxcv', false, null, '"value" must be a valid relative uri'], | ||
['HTTP://www.example.com/', false, null, '"value" must be a valid relative uri'], | ||
['HTTP://www.example.com', false, null, '"value" must be a valid relative uri'], | ||
['http://www.ExAmPlE.com/', false, null, '"value" must be a valid relative uri'], | ||
['http://user:[email protected]/', false, null, '"value" must be a valid relative uri'], | ||
['http://USER:[email protected]/', false, null, '"value" must be a valid relative uri'], | ||
['http://[email protected]/', false, null, '"value" must be a valid relative uri'], | ||
['http://user%[email protected]/', false, null, '"value" must be a valid relative uri'], | ||
['http://x.com/path?that%27s#all,%20folks', false, null, '"value" must be a valid relative uri'], | ||
['HTTP://X.COM/Y', false, null, '"value" must be a valid relative uri'], | ||
['http://www.narwhaljs.org/blog/categories?id=news', false, null, '"value" must be a valid relative uri'], | ||
['http://mt0.google.com/vt/lyrs=m@114&hl=en&src=api&x=2&y=2&z=3&s=', false, null, '"value" must be a valid relative uri'], | ||
['http://mt0.google.com/vt/lyrs=m@114???&hl=en&src=api&x=2&y=2&z=3&s=', false, null, '"value" must be a valid relative uri'], | ||
['http://user:[email protected]/vt/lyrs=m@114???&hl=en&src=api&x=2&y=2&z=3&s=', false, null, '"value" must be a valid relative uri'], | ||
['http://_jabber._tcp.google.com:80/test', false, null, '"value" must be a valid relative uri'], | ||
['http://user:pass@_jabber._tcp.google.com:80/test', false, null, '"value" must be a valid relative uri'], | ||
['http://[fe80::1]/a/b?a=b#abc', false, null, '"value" must be a valid relative uri'], | ||
['http://user:password@[3ffe:2a00:100:7031::1]:8080', false, null, '"value" must be a valid relative uri'], | ||
['coap://[1080:0:0:0:8:800:200C:417A]:61616/', false, null, '"value" must be a valid relative uri'], | ||
['git+http://github.com/joyent/node.git', false, null, '"value" must be a valid relative uri'], | ||
['http://bucket_name.s3.amazonaws.com/image.jpg', false, null, '"value" must be a valid relative uri'], | ||
['dot.test://foo/bar', false, null, '"value" must be a valid relative uri'], | ||
['svn+ssh://foo/bar', false, null, '"value" must be a valid relative uri'], | ||
['dash-test://foo/bar', false, null, '"value" must be a valid relative uri'], | ||
['xmpp:[email protected]', false, null, '"value" must be a valid relative uri'], | ||
['http://atpass:foo%[email protected]:8080/path?search=foo#bar', false, null, '"value" must be a valid relative uri'], | ||
['javascript:alert(\'hello\');', false, null, '"value" must be a valid relative uri'], // eslint-disable-line no-script-url | ||
['file://localhost/etc/node/', false, null, '"value" must be a valid relative uri'], | ||
['file:///etc/node/', false, null, '"value" must be a valid relative uri'], | ||
['http://USER:[email protected]/', false, null, '"value" must be a valid relative uri'], | ||
['mailto:local1@domain1?query1', false, null, '"value" must be a valid relative uri'], | ||
['http://example/a/b?c/../d', false, null, '"value" must be a valid relative uri'], | ||
['http://example/x%2Fabc', false, null, '"value" must be a valid relative uri'], | ||
['http://a/b/c/d;p=1/g;x=1/y', false, null, '"value" must be a valid relative uri'], | ||
['http://a/b/c/g#s/../x', false, null, '"value" must be a valid relative uri'], | ||
['http://a/b/c/.foo', false, null, '"value" must be a valid relative uri'], | ||
['http://example.com/b//c//d;p?q#blarg', false, null, '"value" must be a valid relative uri'], | ||
['g:h', false, null, '"value" must be a valid relative uri'], | ||
['http://a/b/c/g', false, null, '"value" must be a valid relative uri'], | ||
['http://a/b/c/g/', false, null, '"value" must be a valid relative uri'], | ||
['http://a/g', false, null, '"value" must be a valid relative uri'], | ||
['http://g', false, null, '"value" must be a valid relative uri'], | ||
['http://a/b/c/d;p?y', false, null, '"value" must be a valid relative uri'], | ||
['http://a/b/c/g?y', false, null, '"value" must be a valid relative uri'], | ||
['http://a/b/c/d;p?q#s', false, null, '"value" must be a valid relative uri'], | ||
['http://a/b/c/g#s', false, null, '"value" must be a valid relative uri'], | ||
['http://a/b/c/g?y#s', false, null, '"value" must be a valid relative uri'], | ||
['http://a/b/c/;x', false, null, '"value" must be a valid relative uri'], | ||
['http://a/b/c/g;x', false, null, '"value" must be a valid relative uri'], | ||
['http://a/b/c/g;x?y#s', false, null, '"value" must be a valid relative uri'], | ||
['http://a/b/c/d;p?q', false, null, '"value" must be a valid relative uri'], | ||
['http://a/b/c/', false, null, '"value" must be a valid relative uri'], | ||
['http://a/b/', false, null, '"value" must be a valid relative uri'], | ||
['http://a/b/g', false, null, '"value" must be a valid relative uri'], | ||
['http://a/', false, null, '"value" must be a valid relative uri'], | ||
['http://a/g', false, null, '"value" must be a valid relative uri'], | ||
['http://a/g', false, null, '"value" must be a valid relative uri'], | ||
['file:/asda', false, null, '"value" must be a valid relative uri'], | ||
['qwerty', true], | ||
['invalid uri', false, null, '"value" must be a valid relative uri'], | ||
['1http://google.com', false, null, '"value" must be a valid relative uri'], | ||
['http://testdomain`,.<>/?\'";{}][++\\|~!@#$%^&*().org', false, null, '"value" must be a valid relative uri'], | ||
['', false, null, '"value" is not allowed to be empty'], | ||
['(╯°□°)╯︵ ┻━┻', false, null, '"value" must be a valid relative uri'], | ||
['one/two/three?value=abc&value2=123#david-rules', true], | ||
['//username:[email protected]/one/two/three?value=abc&value2=123#david-rules', true], | ||
['http://a\r" \t\n<\'b:b@c\r\nd/e?f', false, null, '"value" must be a valid relative uri'], | ||
['/absolute', true] | ||
], done); | ||
}); | ||
}); | ||
|
||
describe('truncate()', () => { | ||
|