<?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>Forem: zhihu wu</title>
    <description>The latest articles on Forem by zhihu wu (@zhihu_wu_dea1d82af01a04d7).</description>
    <link>https://forem.com/zhihu_wu_dea1d82af01a04d7</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.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3921997%2Fa775d61f-ed57-461b-ac46-ed108350189e.png</url>
      <title>Forem: zhihu wu</title>
      <link>https://forem.com/zhihu_wu_dea1d82af01a04d7</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/zhihu_wu_dea1d82af01a04d7"/>
    <language>en</language>
    <item>
      <title>URL Encoding: The Developer's Swiss Army Knife You're Probably Using Wrong</title>
      <dc:creator>zhihu wu</dc:creator>
      <pubDate>Sat, 09 May 2026 14:51:15 +0000</pubDate>
      <link>https://forem.com/zhihu_wu_dea1d82af01a04d7/url-encoding-the-developers-swiss-army-knife-youre-probably-using-wrong-1nnj</link>
      <guid>https://forem.com/zhihu_wu_dea1d82af01a04d7/url-encoding-the-developers-swiss-army-knife-youre-probably-using-wrong-1nnj</guid>
      <description>&lt;p&gt;URL Encoding: The Developer's Swiss Army Knife You're Probably Using Wrong&lt;/p&gt;

&lt;p&gt;If you've built anything that touches the web, you've dealt with URL encoding. And if you're honest, you've probably Googled "encodeURI vs encodeURIComponent" at least five times this year. I know I have.&lt;/p&gt;

&lt;p&gt;Here's the mental model that finally made it stick for me:&lt;/p&gt;

&lt;h3&gt;
  
  
  The TL;DR
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;encodeURI()&lt;/code&gt; = "I'm encoding a complete URL" → keeps structural chars like &lt;code&gt;/ ? &amp;amp; #&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;encodeURIComponent()&lt;/code&gt; = "I'm encoding ONE piece of data" → encodes EVERYTHING except &lt;code&gt;A-Z a-z 0-9 - _ . ! ~ * ' ( )&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  When Things Go Wrong
&lt;/h3&gt;

&lt;p&gt;Last week I spent an hour debugging a 500 error from a payment gateway. The culprit? I used &lt;code&gt;encodeURI()&lt;/code&gt; on a query parameter that contained a &lt;code&gt;#&lt;/code&gt; character. The browser interpreted everything after &lt;code&gt;#&lt;/code&gt; as a fragment identifier and never sent it to the server. &lt;code&gt;encodeURIComponent()&lt;/code&gt; would have caught it.&lt;/p&gt;

&lt;h3&gt;
  
  
  The 3 Rules I Now Live By
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Query string values&lt;/strong&gt; → ALWAYS &lt;code&gt;encodeURIComponent()&lt;/code&gt;. No exceptions.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Full URLs&lt;/strong&gt; → &lt;code&gt;encodeURI()&lt;/code&gt;, but only if you're sure no component contains special chars.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;When in doubt&lt;/strong&gt; → &lt;code&gt;encodeURIComponent()&lt;/code&gt;. Worst case: you encode too much. Best case: you avoid a bug.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  A Free Tool for When You're Lazy
&lt;/h3&gt;

&lt;p&gt;Sometimes I just want to paste a gnarly URL and see what happens — especially when it's 200 characters long and I don't want to open DevTools. I built a &lt;a href="https://codetoolbox.pro/tools/url-encoder.html" rel="noopener noreferrer"&gt;free URL encoder/decoder&lt;/a&gt; that runs entirely in the browser. No uploads, no ads, no signup. Just paste and encode.&lt;/p&gt;

&lt;p&gt;What URL encoding footgun have you stepped on? I'd love to hear your war stories in the comments.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>javascript</category>
      <category>programming</category>
      <category>tutorial</category>
    </item>
  </channel>
</rss>
