freeCodeCamp/freeCodeCamp

Escaping HTML entities

Ouverte

#63 788 ouverte le 12 nov. 2025

 (22 commentaires) (0 réaction) (0 personne assignée)TypeScript (44 572 forks)batch import
Good first issueUIiOS

Métriques du dépôt

Stars
 (444 744 étoiles)
Métriques de merge PR
 (Métriques PR en attente)

Description

Describe the Issue

We have a challenge that asks campers to replace symbols like & with the relevant HTML entity &. It's a neat little challenge, BUUUUUUT...

The in-app console we render sanitises the entities back to HTML. So with correct code, campers still see & instead of &.

https://imgur.com/a/xxjSSW2

Affected Page

https://www.freecodecamp.org/learn/full-stack-developer/lab-html-entitiy-converter/implement-an-html-entity-converter

Steps to Reproduce

  1. Go to https://www.freecodecamp.org/learn/full-stack-developer/lab-html-entitiy-converter/implement-an-html-entity-converter
  2. Enter the following code.
  3. Open browser console.
  4. See different results.
function convertHTML(str) {
  let newStr = "";
  for (let char of str) {
    if (char == "&") {
      newStr += "&";
    } else if (char == "<") {
      newStr += "&lt;";
    } else if (char == ">") {
      newStr += "&gt;";
    } else if (char == '"') {
      newStr += "&quot;";
    } else if (char == "'") {
      newStr += "&apos;";
    } else {
      newStr += char;
    }
  }
  return newStr;
}

console.log(convertHTML("Dolce & Gabbana"));

Expected behavior

The in-app console should render `Dolce & Gabanna

Screenshots

No response

System

Irrelevant

Additional context

https://www.reddit.com/r/FreeCodeCamp/comments/1ovgdgm/current_javascript_version_autoconvert_makes/

Guide contributeur