-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SHIBUI-806 Added validation for metadata URL
- Loading branch information
Showing
8 changed files
with
60 additions
and
49 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
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 |
---|---|---|
@@ -1,5 +1,3 @@ | ||
import { AbstractControl } from '@angular/forms'; | ||
|
||
export const URL_REGEX = /^(?:http(s)?:\/\/)?[\w.-]+(?:\.[\w\.-]+)+[\w\-\._~:/?#[\]@!\$&'\(\)\*\+,;=.]+$/; | ||
export const EMAIL_REGEX = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{1,})+$/; | ||
export const INTEGER_REGEX = /^[0-9]+$/; |
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 |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { UriValidator } from './uri.validator'; | ||
import { FormControl } from '@angular/forms'; | ||
|
||
describe('UriValidator class', () => { | ||
describe('isUri method', () => { | ||
it('should return false if invalid', () => { | ||
expect(UriValidator.isUri('foo')).toBe(false); | ||
}); | ||
|
||
it('should return true if valid', () => { | ||
expect(UriValidator.isUri('http://foo.bar')).toBe(true); | ||
}); | ||
}); | ||
|
||
describe('uri method', () => { | ||
it('should return a validation object if invalid', () => { | ||
let form: FormControl = new FormControl('foo'); | ||
expect(UriValidator.uri(form)).toEqual({uri: true}); | ||
}); | ||
|
||
it('should return null if valid', () => { | ||
let form: FormControl = new FormControl('http://goo.gle'); | ||
expect(UriValidator.uri(form)).toBeNull(); | ||
}); | ||
}); | ||
}); |
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 |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { AbstractControl, ValidationErrors } from '@angular/forms'; | ||
|
||
export class UriValidator { | ||
static uri(control: AbstractControl): ValidationErrors | null { | ||
return UriValidator.isUri(control.value) ? null : { uri: true }; | ||
} | ||
|
||
static isUri(value: string): boolean { | ||
try { | ||
let url = new URL(value); | ||
} catch (err) { | ||
return false; | ||
} | ||
return true; | ||
} | ||
} | ||
|
||
export default UriValidator; |