Skip to content

Commit

Permalink
Prevent invalid slugs from causing redirects in org settings (#2004)
Browse files Browse the repository at this point in the history
Also improves the slug editing experience by partially-slugifying the
value as it's entered.

Previously, submitting a org slug value of ".." or similar would cause
the frontend to redirect to a "page not found" page, with all accessible
links leading to only `/account/settings`. This also causes the backend
to reset the org slug to one generated from the org name on a reload.

---------

Co-authored-by: sua yoo <[email protected]>
  • Loading branch information
emma-sg and SuaYoo authored Aug 8, 2024
1 parent ed9038f commit 2b5f964
Showing 1 changed file with 14 additions and 4 deletions.
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 ? msg("URL Identifier too short") : "",
);
}

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

Expand Down

0 comments on commit 2b5f964

Please sign in to comment.