Skip to content

Commit

Permalink
SHIBUI-1391 Updated regex test
Browse files Browse the repository at this point in the history
  • Loading branch information
rmathis committed Sep 12, 2019
1 parent b7d829c commit 4a1a258
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
<translate-i18n key="message.required-for-regex">Required for Regex</translate-i18n>
&nbsp;
</small>
<small class="form-text text-danger px-2" *ngIf="hasErrors$ | async">
<small class="form-text text-danger" *ngIf="hasErrors$ | async">
<ng-container *ngFor="let error of errors$ | async; let first=first;">
<ng-container *ngIf="!first">, </ng-container>
<translate-i18n [key]="error.message">{{ error.message }}</translate-i18n>
Expand Down
4 changes: 2 additions & 2 deletions ui/src/app/shared/validation/regex.validator.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ describe('RegexValidator', () => {
expect(RegexValidator.isValidRegex(')')).toBe(false);
});

it('should return false if the regex doesnt begin and end with slashes', () => {
expect(RegexValidator.isValidRegex('abc')).toBe(false);
it('should return true even if the regex doesnt begin and end with slashes', () => {
expect(RegexValidator.isValidRegex('abc')).toBe(true);
});
});
});
6 changes: 2 additions & 4 deletions ui/src/app/shared/validation/regex.validator.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
const regexChecker = new RegExp('^\/|\/$', 'g');

export class RegexValidator {
static isValidRegex(pattern: string): boolean {
if (!pattern) {
return true;
return false;
}
let regex;
try {
regex = new RegExp(pattern);
} catch (err) {
return false;
}
return regexChecker.test(pattern);
return true;
}
}

Expand Down

0 comments on commit 4a1a258

Please sign in to comment.