Skip to content

fix: decode URI-encoded slugs for non-ASCII URL support - #115

Merged
ascorbic merged 6 commits into
emdash-cms:mainfrom
Hari-Bonda:fix/decode-uri-slug
Apr 12, 2026
Merged

ascorbic merged 6 commits into
emdash-cms:mainfrom
Hari-Bonda:fix/decode-uri-slug

Conversation

@Hari-Bonda

@Hari-Bonda Hari-Bonda commented Apr 2, 2026 •

Copy link
Copy Markdown
Contributor

What does this PR do?

Slugs containing non-ASCII characters (e.g. Telugu, Hindi, CJK) are percent-encoded by browsers when requested (e.g. మేష-రాసి becomes %e0%b0%ae%e0%b1%87%e0%b0%b7-%e0%b0%b0%e0%b0%be%e0%b0%b8%e0%b0%bf). Astro.params.slug can return the encoded form on Cloudflare Workers, causing database lookups to fail with a 404.

Applied decodeURIComponent() to all [slug].astro pages across all templates and demos (39 files).

Reproduction

  1. Create a post with a non-Latin slug (e.g. Telugu: మేష-రాసి)
  2. Navigate to the post URL — the browser percent-encodes the Telugu characters
  3. The page returns 404 because the encoded slug doesn't match the DB entry

Fix

-const { slug } = Astro.params;
+const { slug: rawSlug } = Astro.params;
+const slug = rawSlug ? decodeURIComponent(rawSlug) : undefined;

This ensures the slug is decoded before being used in database queries, so non-Latin URLs resolve correctly.

Type of change

  • Bug fix
  • Feature (requires maintainer-approved Discussion)
  • Refactor (no behavior change)
  • Translation
  • Documentation
  • Performance improvement
  • Tests
  • Chore (dependencies, CI, tooling)

Checklist

AI-generated code disclosure

  • This PR includes AI-generated code

Screenshots / test output

  • Posts with ASCII slugs load correctly
  • Posts with non-ASCII slugs (Telugu, Hindi, CJK) now resolve correctly instead of 404
  • Category/tag/page routes with non-ASCII slugs work
  • 404 still works for non-existent slugs

🤖 Generated with Claude Code

Slugs containing non-ASCII characters (e.g. Telugu, Hindi, CJK) are
percent-encoded by browsers when requested. Astro.params.slug can return
the encoded form, causing database lookups to fail with a 404.

Apply decodeURIComponent() to all [slug].astro pages across templates
and demos so non-Latin slugs resolve correctly.

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
@changeset-bot

changeset-bot Bot commented Apr 2, 2026 •

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: f45be07

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
@github-actions

github-actions Bot commented Apr 2, 2026 •

Copy link
Copy Markdown
Contributor

All contributors have signed the CLA ✍️ ✅
Posted by the CLA Assistant Lite bot.

@Hari-Bonda

Copy link
Copy Markdown
Contributor Author

Changeset added in 3c6f9dd — patch bump for all 9 affected packages.

@ascorbic ascorbic left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if we should export a helper to do this, instead of repeating the same code everywhere

Comment thread .changeset/hungry-pianos-turn.md Outdated
Comment on lines +2 to +10
"@emdash-cms/demo-cloudflare": patch
"@emdash-cms/playground": patch
"emdash-plugins-demo": patch
"@emdash-cms/demo-postgres": patch
"@emdash-cms/demo-preview": patch
"emdash-demo": patch
"@emdash-cms/template-blog-cloudflare": patch
"@emdash-cms/template-blog": patch
"@emdash-cms/template-portfolio-cloudflare": patch

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are all private packages that aren't published to npm, so don't need a changeset

@github-actions

github-actions Bot commented Apr 5, 2026

Copy link
Copy Markdown
Contributor

Overlapping PRs

This PR modifies files that are also changed by other open PRs:

This may cause merge conflicts or duplicated work. A maintainer will coordinate.

@pkg-pr-new

pkg-pr-new Bot commented Apr 5, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

@emdash-cms/admin

npm i https://pkg.pr.new/@emdash-cms/admin@115

@emdash-cms/auth

npm i https://pkg.pr.new/@emdash-cms/auth@115

@emdash-cms/blocks

npm i https://pkg.pr.new/@emdash-cms/blocks@115

@emdash-cms/cloudflare

npm i https://pkg.pr.new/@emdash-cms/cloudflare@115

emdash

npm i https://pkg.pr.new/emdash@115

create-emdash

npm i https://pkg.pr.new/create-emdash@115

@emdash-cms/gutenberg-to-portable-text

npm i https://pkg.pr.new/@emdash-cms/gutenberg-to-portable-text@115

@emdash-cms/x402

npm i https://pkg.pr.new/@emdash-cms/x402@115

@emdash-cms/plugin-ai-moderation

npm i https://pkg.pr.new/@emdash-cms/plugin-ai-moderation@115

@emdash-cms/plugin-atproto

npm i https://pkg.pr.new/@emdash-cms/plugin-atproto@115

@emdash-cms/plugin-audit-log

npm i https://pkg.pr.new/@emdash-cms/plugin-audit-log@115

@emdash-cms/plugin-color

npm i https://pkg.pr.new/@emdash-cms/plugin-color@115

@emdash-cms/plugin-embeds

npm i https://pkg.pr.new/@emdash-cms/plugin-embeds@115

@emdash-cms/plugin-forms

npm i https://pkg.pr.new/@emdash-cms/plugin-forms@115

@emdash-cms/plugin-webhook-notifier

npm i https://pkg.pr.new/@emdash-cms/plugin-webhook-notifier@115

commit: f45be07

Export a shared decodeSlug() utility from the core package instead of
repeating inline decodeURIComponent() in every [slug].astro file.
Remove changeset since affected packages are all private/unpublished.

Addresses review feedback from @ascorbic on PR #115.

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
@Hari-Bonda

Copy link
Copy Markdown
Contributor Author

Hi @ascorbic, thanks for the review! I've addressed your feedback:

  1. Extracted a shared decodeSlug() helper — exported from the core emdash package (packages/core/src/utils/slugify.ts), so all [slug].astro files now import and use it instead of repeating inline decodeURIComponent().

  2. Removed the changeset — since the affected packages are all private/unpublished.

Just a heads up — I'm not a developer by trade, I'm using Claude to help me contribute. I really wanted this feature for non-ASCII URL support and thought I'd try to help out. This is my first time sending a pull request, so please excuse any mistakes! Happy to make further changes if needed.

@ascorbic

Copy link
Copy Markdown
Member

Hey @Hari-Bonda! This has become conflicted. I'd like to get it in, but it has become conflicted with the main branch. Could you resolve conflicts and we'll get it in.

Resolve import conflicts where our branch added `decodeSlug` and
upstream added `getSiteSettings` — both imports are kept.

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
@Hari-Bonda

Copy link
Copy Markdown
Contributor Author

Hi @ascorbic, thanks for the heads up! I've resolved the merge conflicts with main — the conflicts were in 6 template files where the decodeSlug import overlapped with the new getSiteSettings import. Both are now included.

Ready for another look whenever you get a chance. Thank you for your patience and for helping guide this PR!

@ascorbic

Copy link
Copy Markdown
Member

Thanks! Can you also sign the CLA (see the comment above)

@Hari-Bonda

Copy link
Copy Markdown
Contributor Author

I have read the CLA Document and I hereby sign the CLA

github-actions Bot added a commit that referenced this pull request Apr 12, 2026

@ascorbic ascorbic left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@ascorbic
ascorbic merged commit 9da92eb into emdash-cms:main Apr 12, 2026
27 of 29 checks passed
fmhall pushed a commit to fmhall/emdash that referenced this pull request Apr 13, 2026
* fix: decode URI-encoded slugs for non-ASCII URL support

Slugs containing non-ASCII characters (e.g. Telugu, Hindi, CJK) are
percent-encoded by browsers when requested. Astro.params.slug can return
the encoded form, causing database lookups to fail with a 404.

Apply decodeURIComponent() to all [slug].astro pages across templates
and demos so non-Latin slugs resolve correctly.

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>

* add changeset for decode-uri-slug fix

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>

* refactor: extract decodeSlug helper and remove changeset

Export a shared decodeSlug() utility from the core package instead of
repeating inline decodeURIComponent() in every [slug].astro file.
Remove changeset since affected packages are all private/unpublished.

Addresses review feedback from @ascorbic on PR emdash-cms#115.

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>

---------

Co-authored-by: Claude Opus 4.6 (1M context) <[email protected]>
Co-authored-by: Matt Kane <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants