Skip to content

Commit cc9ba6f

Browse files
committed
fix: lower minimum slug length from 3 to 2 characters
Allows short slugs like 'me', 'go', 'yt' which were previously rejected with a generic 400 error. Updates SlugGenerator regex and length guard, and fixes grid reload on MyLinks page.
1 parent af99891 commit cc9ba6f

4 files changed

Lines changed: 12 additions & 10 deletions

File tree

.gitignore

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,3 @@
1-
## ── Claude Code / Anthropic AI tooling ──────────────────────────────────────
2-
.claude/
3-
CLAUDE.md
4-
.claudeignore
5-
claude.json
6-
71
## ── .NET ─────────────────────────────────────────────────────────────────────
82
# Build results
93
[Dd]ebug/

src/SnipLink.Api/Services/SlugGenerator.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ public sealed class SlugGenerator : ISlugGenerator
1010
// Bytes >= 252 are rejected to eliminate modulo bias.
1111
private const int MaxUnbiased = 252;
1212

13-
// Pre-compiled: lowercase alphanumeric + hyphens, 3-50 chars,
13+
// Pre-compiled: lowercase alphanumeric + hyphens, 2-50 chars,
1414
// no leading/trailing hyphen, no consecutive hyphens.
1515
private static readonly Regex ValidSlugRegex =
16-
new(@"^[a-z0-9]([a-z0-9\-]{1,48}[a-z0-9]|[a-z0-9]?)$",
16+
new(@"^[a-z0-9]([a-z0-9\-]{0,48}[a-z0-9]|[a-z0-9]?)$",
1717
RegexOptions.Compiled);
1818

1919
public string Generate(int length = 7)
@@ -41,7 +41,7 @@ public string Generate(int length = 7)
4141
public bool IsValid(string slug)
4242
{
4343
if (string.IsNullOrEmpty(slug)) return false;
44-
if (slug.Length < 3 || slug.Length > 50) return false;
44+
if (slug.Length < 2 || slug.Length > 50) return false;
4545
return ValidSlugRegex.IsMatch(slug);
4646
}
4747
}

src/SnipLink.Blazor/Components/Pages/MyLinks.razor

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,12 @@
101101
Nav.NavigateTo("/login");
102102
}
103103

104+
protected override async Task OnAfterRenderAsync(bool firstRender)
105+
{
106+
if (firstRender && grid is not null)
107+
await grid.Reload();
108+
}
109+
104110
private async Task LoadData(LoadDataArgs args)
105111
{
106112
isLoading = true;

src/SnipLink.Tests/Unit/SlugGeneratorTests.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ public void Generate_ProducesUniqueSlugs()
2626
}
2727

2828
[Theory]
29+
[InlineData("ab")]
30+
[InlineData("me")]
2931
[InlineData("abc")]
3032
[InlineData("my-link")]
3133
[InlineData("a1b2c3")]
@@ -35,7 +37,7 @@ public void IsValid_AcceptsValidSlugs(string slug)
3537
}
3638

3739
[Theory]
38-
[InlineData("ab")] // too short
40+
[InlineData("a")] // too short
3941
[InlineData("")] // empty
4042
[InlineData("-abc")] // starts with hyphen
4143
[InlineData("abc-")] // ends with hyphen

0 commit comments

Comments
 (0)