-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow repositories with ssh:// (and its short git form), git://, svn://, svn+ssh:// as protocol in URL fields, via a new "repourl" field type. Also, use https:// as the placeholder for URL fields, to drop a hint to the user about the nature of such fields.
- Loading branch information
Showing
5 changed files
with
108 additions
and
11 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 |
---|---|---|
|
@@ -83,7 +83,19 @@ export const checkField = (field, obj, value, required) => { | |
return "This property is required."; | ||
|
||
if (widget == "url" && !validator.isURL(value, {require_protocol: true})) { | ||
return "Not a valid Url"; | ||
return "Not a valid URL"; | ||
} | ||
if (widget == "repourl" | ||
&& !validator.isURL(value, {require_protocol: true}) | ||
// Eg. ssh://example.com/repo.git | ||
// git://example.com/repo.git | ||
// svn://example.com/repo | ||
// svn+ssh://example.com/repo | ||
&& !value.match(/^(ssh|git|svn|svn\+ssh):\/\/(\w+@?)\w+\.\w+.*/) | ||
// Eg. [email protected]:foo/bar.git | ||
// github.com:/foo/bar.git | ||
&& !value.match(/^(\w+@?)\w+\.\w+:.*/)) { | ||
return "Not a valid repository URL"; | ||
} | ||
if (widget == "email" && !validator.isEmail(value)) { | ||
return "Not a valid email"; | ||
|
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 |
---|---|---|
|
@@ -78,40 +78,124 @@ test('URL test', () => { | |
expect(val.checkField('', { | ||
widget: 'url' | ||
}, 'hppp://google.it', true)) | ||
.toBe('Not a valid Url'); | ||
.toBe('Not a valid URL'); | ||
|
||
expect(val.checkField('', { | ||
widget: 'url' | ||
}, 'http://google', true)) | ||
.toBe('Not a valid Url'); | ||
.toBe('Not a valid URL'); | ||
|
||
expect(val.checkField('', { | ||
widget: 'url' | ||
}, 'httpz://google.it', true)) | ||
.toBe('Not a valid Url'); | ||
.toBe('Not a valid URL'); | ||
|
||
expect(val.checkField('', { | ||
widget: 'url' | ||
}, 'http:/google.it', true)) | ||
.toBe('Not a valid Url'); | ||
.toBe('Not a valid URL'); | ||
|
||
expect(val.checkField('', { | ||
widget: 'url' | ||
}, 'https:///google.it', true)) | ||
.toBe('Not a valid Url'); | ||
.toBe('Not a valid URL'); | ||
|
||
expect(val.checkField('', { | ||
widget: 'url' | ||
}, 'http//google.it', true)) | ||
.toBe('Not a valid Url'); | ||
.toBe('Not a valid URL'); | ||
|
||
expect(val.checkField('', { | ||
widget: 'url' | ||
}, 'http:/googleit', true)) | ||
.toBe('Not a valid Url'); | ||
.toBe('Not a valid URL'); | ||
|
||
expect(val.checkField('', { | ||
widget: 'url' | ||
}, 'https://google.it', true)) | ||
.toBeNull(); | ||
}); | ||
|
||
test('repourl validation', () => { | ||
expect(val.checkField('', { | ||
widget: 'repourl' | ||
}, 'hppp://google.it', true)) | ||
.toBe('Not a valid repository URL'); | ||
|
||
expect(val.checkField('', { | ||
widget: 'repourl' | ||
}, 'http://google', true)) | ||
.toBe('Not a valid repository URL'); | ||
|
||
expect(val.checkField('', { | ||
widget: 'repourl' | ||
}, 'httpz://google.it', true)) | ||
.toBe('Not a valid repository URL'); | ||
|
||
expect(val.checkField('', { | ||
widget: 'repourl' | ||
}, 'http:/google.it', true)) | ||
.toBe('Not a valid repository URL'); | ||
|
||
expect(val.checkField('', { | ||
widget: 'repourl' | ||
}, 'https:///google.it', true)) | ||
.toBe('Not a valid repository URL'); | ||
|
||
expect(val.checkField('', { | ||
widget: 'repourl' | ||
}, 'http//google.it', true)) | ||
.toBe('Not a valid repository URL'); | ||
|
||
expect(val.checkField('', { | ||
widget: 'repourl' | ||
}, 'http:/googleit', true)) | ||
.toBe('Not a valid repository URL'); | ||
|
||
expect(val.checkField('', { | ||
widget: 'repourl' | ||
}, 'https://google.it', true)) | ||
.toBeNull(); | ||
|
||
// Valid git scp-like syntax | ||
expect(val.checkField('', { | ||
widget: 'repourl' | ||
}, '[email protected]:foobar/baz.git', true)) | ||
.toBeNull(); | ||
|
||
// Invalid syntax, the username is empty | ||
expect(val.checkField('', { | ||
widget: 'repourl' | ||
}, '@example.com:foobar/baz.git', true)) | ||
.toBe('Not a valid repository URL'); | ||
|
||
// Valid git:// URL | ||
expect(val.checkField('', { | ||
widget: 'repourl' | ||
}, 'git://example.com/foobar/baz.git', true)) | ||
.toBeNull(); | ||
|
||
// Invalid syntax, the match is not at the beginning | ||
expect(val.checkField('', { | ||
widget: 'repourl' | ||
}, 'junk at beginning git://example.com:foobar/baz.git', true)) | ||
.toBe('Not a valid repository URL'); | ||
|
||
// Valid svn:// URL | ||
expect(val.checkField('', { | ||
widget: 'repourl' | ||
}, 'svn://example.com/foobar/baz/', true)) | ||
.toBeNull(); | ||
|
||
// Valid ssh:// URL | ||
expect(val.checkField('', { | ||
widget: 'repourl' | ||
}, 'ssh://example.com/foobar/baz.git', true)) | ||
.toBeNull(); | ||
|
||
// Valid svn+ssh:// URL | ||
expect(val.checkField('', { | ||
widget: 'repourl' | ||
}, 'svn+ssh://example.com/foobar/baz/', true)) | ||
.toBeNull(); | ||
}); |