Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Properly validate repository name in frontend and backend #1178

Merged
merged 3 commits into from
Nov 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ class DatabaseT4CRepository(database.Base):


class CreateT4CRepository(pydantic.BaseModel):
name: str
name: str = pydantic.Field(
pattern="^[-a-zA-Z0-9_]+$", examples=["testrepo"]
)


class T4CRepositoryStatus(str, enum.Enum):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,12 @@
<mat-form-field appearance="fill">
<mat-label>Repository</mat-label>
<input matInput formControlName="t4cRepositoryName" />
<mat-error *ngIf="t4cRepositoryNameControl.errors?.uniqueName"
>Repository already exists</mat-error
>
<mat-error *ngIf="t4cRepositoryNameControl.errors?.uniqueName">
Repository already exists
</mat-error>
<mat-error *ngIf="t4cRepositoryNameControl.errors?.pattern">
The following characters are allowed: A-Z, a-z, 0-9, _, -
</mat-error>
</mat-form-field>
</fieldset>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,13 @@ export class CreateT4cModelNewRepositoryComponent implements OnInit {
t4cInstanceId: new FormControl<number | null>(null, Validators.required),
t4cRepositoryName: new FormControl<string | null>(
{ value: null, disabled: true },
Validators.required,
this.t4cRepoService.asyncNameValidator(),
{
validators: [
Validators.required,
Validators.pattern(/^[-a-zA-Z0-9_]+$/),
],
asyncValidators: this.t4cRepoService.asyncNameValidator(),
},
),
t4cProjectName: new FormControl<string | null>(
{ value: null, disabled: true },
Expand Down
Loading