Skip to content

Commit 8c4b839

Browse files
committed
Changed URL validation
1 parent e87776c commit 8c4b839

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

src/app/pages/assets/asset-create/asset-create.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@
140140

141141
<mat-form-field class="form-field" color="accent">
142142
<mat-label>Base URL</mat-label>
143-
<input [(ngModel)]="httpDataAddress.baseUrl" [pattern]="urlPattern" matInput required>
143+
<input [(ngModel)]="httpDataAddress.baseUrl" matInput required>
144144
</mat-form-field>
145145

146146
<mat-form-field class="form-field" color="accent">

src/app/pages/assets/asset-create/asset-create.component.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,6 @@ export class AssetCreateComponent implements OnInit {
103103
config = CKEDITOR_CONFIG
104104
selectedAssetTypeVocabularies: Vocabulary[]
105105

106-
urlPattern: RegExp = /^https?:\/\/(www\.)?[-a-zA-Z0-9@:%._+~#=]{1,256}\.[a-zA-Z]{2,6}\b([-a-zA-Z0-9()@:%_+.~#?&//=]*)$/;
107-
108106
private fetch$ = new BehaviorSubject(null);
109107

110108
ngOnInit(): void {
@@ -370,8 +368,12 @@ export class AssetCreateComponent implements OnInit {
370368
}
371369

372370
validateUrl(): boolean {
373-
const regex = new RegExp(this.urlPattern);
374-
return regex.test(this.httpDataAddress.baseUrl);
371+
try {
372+
var url = new URL(this.httpDataAddress.baseUrl);
373+
} catch (e) {
374+
return false;
375+
}
376+
return url.protocol === "http:" || url.protocol === "https:";
375377
}
376378

377379

0 commit comments

Comments
 (0)