<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Yiftach Freeman</title>
    <description>The latest articles on DEV Community by Yiftach Freeman (@freemangt).</description>
    <link>https://dev.to/freemangt</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4280878%2Ff3578b52-04c9-4759-900e-0c9ced15fb0f.jpg</url>
      <title>DEV Community: Yiftach Freeman</title>
      <link>https://dev.to/freemangt</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/freemangt"/>
    <language>en</language>
    <item>
      <title>Hebrew short links in Next.js: what the server receives and how to read it</title>
      <dc:creator>Yiftach Freeman</dc:creator>
      <pubDate>Thu, 03 Dec 2026 14:23:01 +0000</pubDate>
      <link>https://dev.to/freemangt/hebrew-short-links-in-nextjs-what-the-server-receives-and-how-to-read-it-58lm</link>
      <guid>https://dev.to/freemangt/hebrew-short-links-in-nextjs-what-the-server-receives-and-how-to-read-it-58lm</guid>
      <description>&lt;p&gt;A short link like &lt;code&gt;kip.li/מבצע-חורף&lt;/code&gt; ("winter sale") is what people type and what they read on a poster. The server never sees those letters. This article follows one Next.js 16 App Router codebase through the path a Hebrew back-half takes, from the request line to the database key and back to the screen. Every excerpt is taken from the repo.&lt;/p&gt;

&lt;h2&gt;
  
  
  What actually arrives
&lt;/h2&gt;

&lt;p&gt;A URI is ASCII. Anything else travels as percent-encoded bytes, and the convention for text, codified for IRIs in RFC 3987 and in the WHATWG URL Standard, is to encode it as UTF-8 first and then write each byte as &lt;code&gt;%XX&lt;/code&gt;. Hebrew letters are two bytes each in UTF-8, so &lt;code&gt;מ&lt;/code&gt; (U+05DE) becomes &lt;code&gt;%D7%9E&lt;/code&gt;, and the request looks like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight http"&gt;&lt;code&gt;&lt;span class="no"&gt;GET&lt;/span&gt; &lt;span class="o"&gt;/%&lt;/span&gt;&lt;span class="no"&gt;D7&lt;/span&gt;&lt;span class="o"&gt;%&lt;/span&gt;&lt;span class="mf"&gt;9E&lt;/span&gt;&lt;span class="o"&gt;%&lt;/span&gt;&lt;span class="no"&gt;D7&lt;/span&gt;&lt;span class="o"&gt;%&lt;/span&gt;&lt;span class="mi"&gt;91&lt;/span&gt;&lt;span class="o"&gt;%&lt;/span&gt;&lt;span class="no"&gt;D7&lt;/span&gt;&lt;span class="o"&gt;%&lt;/span&gt;&lt;span class="no"&gt;A6&lt;/span&gt;&lt;span class="o"&gt;%&lt;/span&gt;&lt;span class="no"&gt;D7&lt;/span&gt;&lt;span class="o"&gt;%&lt;/span&gt;&lt;span class="no"&gt;A2&lt;/span&gt;&lt;span class="o"&gt;-%&lt;/span&gt;&lt;span class="no"&gt;D7&lt;/span&gt;&lt;span class="o"&gt;%&lt;/span&gt;&lt;span class="mi"&gt;97&lt;/span&gt;&lt;span class="o"&gt;%&lt;/span&gt;&lt;span class="no"&gt;D7&lt;/span&gt;&lt;span class="o"&gt;%&lt;/span&gt;&lt;span class="mi"&gt;95&lt;/span&gt;&lt;span class="o"&gt;%&lt;/span&gt;&lt;span class="no"&gt;D7&lt;/span&gt;&lt;span class="o"&gt;%&lt;/span&gt;&lt;span class="no"&gt;A8&lt;/span&gt;&lt;span class="o"&gt;%&lt;/span&gt;&lt;span class="no"&gt;D7&lt;/span&gt;&lt;span class="o"&gt;%&lt;/span&gt;&lt;span class="no"&gt;A3&lt;/span&gt; &lt;span class="no"&gt;HTTP&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="mf"&gt;1.1&lt;/span&gt;
&lt;span class="nc"&gt;Host&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;kip&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;li&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Browsers do the encoding before the request leaves, and most display the decoded form in the address bar. Punycode has no part in this: IDNA and Punycode (RFC 5891, RFC 3492) apply to domain labels only. A Hebrew host becomes &lt;code&gt;xn--...&lt;/code&gt;; a Hebrew path becomes percent escapes. The same codebase does both: its destination normaliser converts Hebrew hosts to punycode, while the back-half stays UTF-8 in the path.&lt;/p&gt;

&lt;p&gt;Inside a route handler, &lt;code&gt;req.nextUrl&lt;/code&gt; is built on the WHATWG parser, so &lt;code&gt;pathname&lt;/code&gt; is already the encoded form. &lt;code&gt;new URL("https://kip.li/מבצע-חורף+").pathname&lt;/code&gt; returns &lt;code&gt;/%D7%9E%D7%91%D7%A6%D7%A2-%D7%97%D7%95%D7%A8%D7%A3+&lt;/code&gt;. The &lt;code&gt;+&lt;/code&gt; survives as a literal: it is a sub-delimiter allowed in a path (RFC 3986, section 3.3). It means "space" only in form-encoded query strings.&lt;/p&gt;

&lt;p&gt;There is a third shape. A comment in the parser notes that some apps double-encode Hebrew, turning each &lt;code&gt;%&lt;/code&gt; into &lt;code&gt;%25&lt;/code&gt;, and the test suite holds such a case: &lt;code&gt;%25D7%2597%25D7%25A0%25D7%2595%25D7%25AA&lt;/code&gt; must resolve to &lt;code&gt;חנות&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  One function owns decoding
&lt;/h2&gt;

&lt;p&gt;The redirect route, &lt;code&gt;src/app/[slug]/route.ts&lt;/code&gt;, ignores its own &lt;code&gt;slug&lt;/code&gt; parameter. It reads the path and hands the raw string to a shared engine:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;backHalf&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;req&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;NextRequest&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;req&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;nextUrl&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;pathname&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;replace&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;/^&lt;/span&gt;\&lt;span class="o"&gt;/+/&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;""&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Next decodes dynamic route parameters before the handler runs. If the framework decodes for some routes and your code decodes for others, you lose track of how many times a string has been decoded, and double-encoded input becomes ambiguous. Taking the raw path keeps decoding in one place. The same engine also serves customer domains through a catch-all route whose segments arrive already decoded, so the parser accepts both forms; text without a &lt;code&gt;%XX&lt;/code&gt; sequence passes through unchanged.&lt;/p&gt;

&lt;p&gt;That parser is &lt;code&gt;parseBackHalf&lt;/code&gt; in &lt;code&gt;src/lib/redirect/parse.ts&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;parseBackHalf&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;raw&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="kc"&gt;undefined&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;BackHalf&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;raw&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="n"&gt;value&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;safeDecode&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;String&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;raw&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;normalize&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"NFKC"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;trim&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="n"&gt;value&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;value&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;replace&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;/^&lt;/span&gt;\&lt;span class="o"&gt;/+/&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;""&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;replace&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;\&lt;span class="o"&gt;/+&lt;/span&gt;$&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;""&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="n"&gt;value&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="n"&gt;value&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;includes&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"/"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="n"&gt;preview&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;value&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;endsWith&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"+"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;preview&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="n"&gt;value&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;value&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;replace&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;\&lt;span class="o"&gt;++&lt;/span&gt;$&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;""&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="n"&gt;value&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="n"&gt;value&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;length&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;200&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="c1"&gt;// Same alphabet as validateSlug (letters in any script, digits, combining marks, "-" and "_").&lt;/span&gt;
  &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!/^&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;\&lt;span class="n"&gt;p&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="no"&gt;L&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;\&lt;span class="n"&gt;p&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="no"&gt;N&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;\&lt;span class="n"&gt;p&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="no"&gt;L&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;\&lt;span class="n"&gt;p&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="no"&gt;N&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;\&lt;span class="n"&gt;p&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="no"&gt;M&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="n"&gt;_&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;$&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;u&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;test&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;value&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;slug&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;value&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;preview&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;safeDecode&lt;/code&gt; wraps &lt;code&gt;decodeURIComponent&lt;/code&gt; so it never throws, and repeats it while a &lt;code&gt;%XX&lt;/code&gt; sequence remains, at most twice. That is a deliberate exception to the usual rule of decoding exactly once. It is safe here only because of the last line: the decoded value has to match a strict allow-list of letters, digits, combining marks, &lt;code&gt;_&lt;/code&gt; and &lt;code&gt;-&lt;/code&gt;. Anything that decodes into &lt;code&gt;/&lt;/code&gt;, &lt;code&gt;%&lt;/code&gt;, &lt;code&gt;.&lt;/code&gt; or whitespace is rejected rather than interpreted, so a second pass cannot smuggle a path separator in through &lt;code&gt;%252F&lt;/code&gt;. Without an allow-list after it, a second decode is a bug.&lt;/p&gt;

&lt;p&gt;Order matters too. Normalisation runs after decoding, because there is nothing to normalise in &lt;code&gt;%D7%9E&lt;/code&gt;. Trimming and the slash checks run after normalisation, so a full-width slash (U+FF0F), which NFKC folds to &lt;code&gt;/&lt;/code&gt;, is caught like a plain one.&lt;/p&gt;

&lt;h2&gt;
  
  
  Normalising into a lookup key
&lt;/h2&gt;

&lt;p&gt;Each link stores two strings: the back-half as its creator typed it, and a lookup key with a unique constraint per domain. The key comes from &lt;code&gt;src/lib/links/slug.ts&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="no"&gt;SLUG_PATTERN&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;/^&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;\&lt;span class="n"&gt;p&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="no"&gt;L&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;\&lt;span class="n"&gt;p&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="no"&gt;N&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;\&lt;span class="n"&gt;p&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="no"&gt;L&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;\&lt;span class="n"&gt;p&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="no"&gt;N&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;\&lt;span class="n"&gt;p&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="no"&gt;M&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="n"&gt;_&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;$&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;u&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="cm"&gt;/** Lookup key: Unicode-normalised and lower-cased, so KIP.li/Sale and kip.li/sale are the same link. */&lt;/span&gt;
&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;slugKey&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;slug&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;slug&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;normalize&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"NFKC"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;toLowerCase&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Every read goes through &lt;code&gt;slugKey&lt;/code&gt;: the redirect, the preview page, the availability check and the reserved-word check. What NFKC does for Hebrew is narrow but real. The presentation forms block (U+FB1D to U+FB4F) folds back to ordinary letters: the wide alef U+FB21 becomes &lt;code&gt;א&lt;/code&gt;, and precomposed pointed letters such as U+FB2B split into a base letter plus a combining point. Full-width Latin folds too, so &lt;code&gt;ｓａｌｅ&lt;/code&gt; becomes &lt;code&gt;sale&lt;/code&gt;. NFKC does not remove niqqud, so &lt;code&gt;שלום&lt;/code&gt; and &lt;code&gt;שָׁלוֹם&lt;/code&gt; are two different keys. &lt;code&gt;toLowerCase()&lt;/code&gt; does nothing to Hebrew, which has no case; it exists for Latin back-halves.&lt;/p&gt;

&lt;p&gt;The pattern also defines some edges worth knowing:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The first character must be a letter or digit, so a back-half cannot start with a bare vowel point.&lt;/li&gt;
&lt;li&gt;Only the ASCII hyphen-minus is allowed. The Hebrew maqaf (U+05BE) and gershayim (U+05F4, as in &lt;code&gt;צה״ל&lt;/code&gt;) are punctuation in Unicode, so back-halves containing them are refused at creation and never match at redirect.&lt;/li&gt;
&lt;li&gt;Length is checked in code points by &lt;code&gt;validateSlug&lt;/code&gt; (&lt;code&gt;[...slug].length&lt;/code&gt;, between 2 and 60). Niqqud counts: &lt;code&gt;שָׁלוֹם&lt;/code&gt; is seven code points. The parser's 200-unit cap is a cheap guard before the regex, not the real limit.&lt;/li&gt;
&lt;li&gt;Reserved words cover the app's own paths and a few Hebrew ones (&lt;code&gt;אודות&lt;/code&gt;, &lt;code&gt;מחירים&lt;/code&gt;, &lt;code&gt;בלוג&lt;/code&gt; and others), compared through &lt;code&gt;slugKey&lt;/code&gt;, so case and width variants are caught as well.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The proxy (&lt;code&gt;src/proxy.ts&lt;/code&gt;) handles the case question for the site's own pages: &lt;code&gt;/Pricing&lt;/code&gt; gets a 308 to &lt;code&gt;/pricing&lt;/code&gt;. When it lower-cases a path it skips percent escapes, so the hex digits of an encoded Hebrew segment keep their spelling.&lt;/p&gt;

&lt;h2&gt;
  
  
  The "+" preview
&lt;/h2&gt;

&lt;p&gt;Appending &lt;code&gt;+&lt;/code&gt; to a short link shows where it leads without going there. The parser strips any run of trailing &lt;code&gt;+&lt;/code&gt; and sets &lt;code&gt;preview&lt;/code&gt;. Because decoding happens first, &lt;code&gt;abc%2B&lt;/code&gt; is a preview request too, and &lt;code&gt;+&lt;/code&gt; on its own is rejected. The engine then redirects to the preview page and encodes the back-half again on the way out:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;parsed&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;preview&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nf"&gt;redirectTo&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;appPage&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sb"&gt;`/link/preview/${encodeURIComponent(parsed.slug)}`&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Broken escapes
&lt;/h2&gt;

&lt;p&gt;A link copied with its last character cut off can end mid-letter: &lt;code&gt;/%D7%A7%D7&lt;/code&gt; has a complete &lt;code&gt;ק&lt;/code&gt; and then the first byte of another letter. &lt;code&gt;decodeURIComponent&lt;/code&gt; throws &lt;code&gt;URIError&lt;/code&gt; on it. Because Next decodes route parameters before the route runs, a comment in the code reports that such a request ended as the framework's bare 500 screen on Vercel and a bare 400 on its own server, before any application code could answer.&lt;/p&gt;

&lt;p&gt;The proxy runs first. &lt;code&gt;repairBrokenEscapes&lt;/code&gt; tries to decode each path segment and replaces any segment that fails with &lt;code&gt;~&lt;/code&gt;, a character no back-half can start with, then answers with a 307 to the repaired path. There the route treats it like any unknown link. The code uses a redirect, not a rewrite, because after a rewrite Next still reads route parameters from the address the visitor asked for.&lt;/p&gt;

&lt;h2&gt;
  
  
  Showing it back
&lt;/h2&gt;

&lt;p&gt;Display is a bidi problem (Unicode Standard Annex #9). A Latin host followed by a Hebrew path, with digits and dashes in between, will reorder in ways nobody typed. The project's &lt;code&gt;.url&lt;/code&gt; class sets &lt;code&gt;direction: ltr&lt;/code&gt; and &lt;code&gt;unicode-bidi: isolate&lt;/code&gt;. That was not enough: inside a left-to-right box the bidi algorithm still groups digits and dashes with a neighbouring Hebrew run, and &lt;code&gt;מבצע-2026-קיץ&lt;/code&gt; showed its words swapped. The short-link component now wraps each Hebrew run in its own &lt;code&gt;&amp;lt;bdi dir="rtl"&amp;gt;&lt;/code&gt; and leaves everything between them left to right.&lt;/p&gt;

&lt;p&gt;Headers need the opposite treatment. HTTP field values are bytes, and the &lt;code&gt;Headers&lt;/code&gt; class in Node accepts only characters up to U+00FF. &lt;code&gt;new Headers({ Location: "https://kip.li/מבצע" })&lt;/code&gt; throws a &lt;code&gt;TypeError&lt;/code&gt;. Any &lt;code&gt;Location&lt;/code&gt; built from a Hebrew back-half has to be percent-encoded first, as the preview redirect above does.&lt;/p&gt;

&lt;h2&gt;
  
  
  Summary
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Read the raw path and decode it in one function, a bounded number of times.&lt;/li&gt;
&lt;li&gt;Normalise after decoding and compare on a stored key.&lt;/li&gt;
&lt;li&gt;Validate the decoded value against an allow-list, not a deny-list.&lt;/li&gt;
&lt;li&gt;Turn broken escapes into ordinary dead links before the framework sees them.&lt;/li&gt;
&lt;li&gt;Encode again on the way out, and isolate Hebrew runs when you display a URL.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;I build KIP, a Hebrew-first link shortener at &lt;a href="https://kip.li" rel="noopener noreferrer"&gt;kip.li&lt;/a&gt;, and the code above comes from its repository.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;This article was written with the help of AI and checked against the KIP codebase and the cited specs. I stand behind its content.&lt;/em&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  References
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;RFC 3986, Uniform Resource Identifier (URI): Generic Syntax: &lt;a href="https://www.rfc-editor.org/rfc/rfc3986" rel="noopener noreferrer"&gt;https://www.rfc-editor.org/rfc/rfc3986&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;RFC 3987, Internationalized Resource Identifiers (IRIs): &lt;a href="https://www.rfc-editor.org/rfc/rfc3987" rel="noopener noreferrer"&gt;https://www.rfc-editor.org/rfc/rfc3987&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;WHATWG URL Standard (percent-encode sets, URL parsing): &lt;a href="https://url.spec.whatwg.org/" rel="noopener noreferrer"&gt;https://url.spec.whatwg.org/&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;RFC 3492, Punycode: &lt;a href="https://www.rfc-editor.org/rfc/rfc3492" rel="noopener noreferrer"&gt;https://www.rfc-editor.org/rfc/rfc3492&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;RFC 5891, Internationalized Domain Names in Applications (IDNA): Protocol: &lt;a href="https://www.rfc-editor.org/rfc/rfc5891" rel="noopener noreferrer"&gt;https://www.rfc-editor.org/rfc/rfc5891&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Unicode Standard Annex #15, Unicode Normalization Forms: &lt;a href="https://www.unicode.org/reports/tr15/" rel="noopener noreferrer"&gt;https://www.unicode.org/reports/tr15/&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Unicode Standard Annex #9, Unicode Bidirectional Algorithm: &lt;a href="https://www.unicode.org/reports/tr9/" rel="noopener noreferrer"&gt;https://www.unicode.org/reports/tr9/&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Unicode code chart, Alphabetic Presentation Forms (U+FB00 to U+FB4F): &lt;a href="https://www.unicode.org/charts/PDF/UFB00.pdf" rel="noopener noreferrer"&gt;https://www.unicode.org/charts/PDF/UFB00.pdf&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;RFC 9110, HTTP Semantics, section 5.5 (field values): &lt;a href="https://www.rfc-editor.org/rfc/rfc9110#section-5.5" rel="noopener noreferrer"&gt;https://www.rfc-editor.org/rfc/rfc9110#section-5.5&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Web IDL, ByteString: &lt;a href="https://webidl.spec.whatwg.org/#idl-ByteString" rel="noopener noreferrer"&gt;https://webidl.spec.whatwg.org/#idl-ByteString&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>nextjs</category>
      <category>webdev</category>
      <category>i18n</category>
      <category>unicode</category>
    </item>
  </channel>
</rss>
