Skip to content

Escape

Easy — everyone uses thisSecurity

ELI5 — The Vibe Check

Escaping means converting special characters into their safe equivalents before putting them in HTML, SQL, or a shell command. Like turning < into &lt; so the browser shows it as text instead of running it as code. Escaping is context-specific: HTML escaping, SQL escaping, and shell escaping are all different.

Real Talk

Escaping is the process of converting special characters into their escaped equivalents for the current context, preventing injection attacks. HTML escaping converts <, >, &, ', " to HTML entities. SQL escaping uses parameterized queries. Shell escaping uses libraries like shellescape.

Show Me The Code

// HTML escaping prevents XSS
function escapeHtml(str) {
  return str
    .replace(/&/g, '&amp;')
    .replace(/</g, '&lt;')
    .replace(/>/g, '&gt;')
    .replace(/"/g, '&quot;')
    .replace(/'/g, '&#039;');
}

// Most templating engines (Handlebars, Jinja2) escape by default
// {{ userInput }}  ← escaped
// {{{ userInput }}} ← raw, dangerous!

When You'll Hear This

"Escape all user-supplied data before inserting it into HTML." / "Handlebars escapes by default — use triple braces only when you trust the content."

Made with passive-aggressive love by manoga.digital. Powered by Claude.