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

Prevent invalid slugs from causing redirects in org settings #2004

Merged
merged 2 commits into from
Aug 8, 2024
Merged
Changes from 1 commit
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
18 changes: 14 additions & 4 deletions frontend/src/pages/org/settings/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -239,10 +239,7 @@ export class OrgSettings extends TailwindElement {
: this.org.slug
}`,
)}
@sl-input=${(e: InputEvent) => {
const input = e.target as SlInput;
this.slugValue = input.value;
}}
@sl-input=${this.handleSlugInput}
></sl-input>
`,
msg(
Expand Down Expand Up @@ -275,6 +272,19 @@ export class OrgSettings extends TailwindElement {
</div>`;
}

private handleSlugInput(e: InputEvent) {
const input = e.target as SlInput;
// Ideally this would match against the full character map that slugify uses
// but this'll do for most use cases
const end = input.value.match(/[\s*_+~.,()'"!\-:@]$/g) ? "-" : "";
input.value = slugifyStrict(input.value) + end;
this.slugValue = slugifyStrict(input.value);

input.setCustomValidity(
this.slugValue.length < 2 ? "URL Identifier too short" : "",
emma-sg marked this conversation as resolved.
Show resolved Hide resolved
);
}

private renderMembers() {
if (!this.org?.users) return;

Expand Down
Loading