Task: Fix URL decoding in haih-agent

Fix URL decoding in haih-agent

27.08.2026haih agent

Add proper URL/route params decoding in haih-agent so that percent-encoded special characters do not lead to false 404 errors.

Problem

haih-agent experiences the same issue as freecode.academy: URLs with special characters in percent-encoded form can lead to 404 errors even though the corresponding entity exists.

The cause is confirmed: proper URL decoding is missing. In this use case, using decodeURI resolves the issue.

What needs to be done

  1. Locate the common section in haih-agent where URLs/route params/slugs are used for entity lookup or route matching.
  2. Add uniform decoding prior to business logic/lookup so that percent-encoded characters are compared with data in the expected format.
  3. Determine the exact place to apply decodeURI or its equivalent so that the fix works centrally, and projects based on haih-agent are not forced to fix it locally.
  4. Prevent double decoding and errors on already decoded values.
  5. Check the interaction with URL generation/canonical URLs to ensure that encode/decode are symmetric and performed exactly once at the respective boundary.

Example of a problematic case

/comments/topics/dzheneriki-typescript/nu-vot-ts-tebe-govorit-%22ty-zanimaeshsya-figney%22,-i

Before the fix, such a URL may return a 404 due to %22 and other encoded characters. After decoding, the existing page/entity must be found.

Check separately

  • %22 / quotes;
  • Cyrillic characters;
  • spaces and %20;
  • %25 and potential double encoding cases;
  • commas and other valid slug characters;
  • malformed percent-encoding — must not cause the application to crash;
  • already decoded route params — must not break due to re-decoding.

Acceptance Criteria

  • The common source of the problem in haih-agent has been found and fixed.
  • Percent-encoded URLs resolve correctly to existing pages/entities.
  • Confirmed that decodeURI or the chosen equivalent is applied at the correct level and does not lead to double decoding.
  • Incorrect percent-encoding is handled safely and does not cause a 500 error.
  • Regression tests have been added for at least %22, Cyrillic characters, %20, %25, and malformed encoding.
  • Verified that the fix does not break regular URLs without special characters.
  • Where possible, the fix is implemented centrally to automatically resolve the issue in projects using haih-agent.

Ворклоги

Clarification on URI Decoding

After verification, it turned out that decodeURI(asPath) does not cover all the necessary cases.

Concrete example:

/projects/%40prisma-cms/sendmail

is expected to be:

/projects/@prisma-cms/sendmail

However, decodeURI() leaves %40 intact because @ belongs to reserved URI characters, and the entire URI is not fully decoded.

For entity URIs, it is more correct to process the path segment by segment:

  1. First, split the pathname by /, preserving the route structure.
  2. Pass each segment separately through decodeURIComponent().
  3. Reassemble the path.

This way, we get the required decoding %40 -> @ without the risk that an encoded %2F inside a single slug prematurely turns into a structural / and changes the number of route segments.

In other words, the target logic should be segment-aware, for example conceptually:

const uri = pathname
  .split('/')
  .map(segment => decodeURIComponent(segment))
  .join('/')

This is also symmetrical to the current implementation of slugifyUri(), which already works on a segment-by-segment basis.

The current decodeURI(asPath) can be considered an interim fix: it solves cases like %22, but not %40 and other reserved characters if they are part of a slug/entity URI.

A separate URIError is not considered here as part of this task: technical malformed URL errors should be handled separately.

Progress: the fix has been implemented and expanded to the CNC (ChPU) basis

The implementation is completed in the commit: https://github.com/haih-net/agent/commit/1f99a51dd407eb4e58f9e2f83f411a265db2f24c

Incoming URIs are now decoded via decodeURI at key points when working with router.asPath, which eliminates false 404s for existing pages with percent-encoded characters.

At the same time, the work has been expanded to the general URI basis of haih-agent: generation of slugified URIs from the concept name and automatic 301 redirect upon URI changes have been added. This is done as a foundation for the transition of haih-agent-based applications to human-readable URLs.

The practical continuation is SEO/GEO of fi1osof.ru, where current task and project URLs use technical CUIDs. Related task: Upgrade SEO/GEO.