freeCodeCamp / freeCodeCamp/freeCodeCamp
Escaping HTML entities
- Dominant language
- TypeScript
- Stars
- 455k
- Forks
- 46.2k
- Avg merge
- 1d 17h
- Merged PRs (30d)
- 215
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.
```js
function convertHTML(str) {
let newStr = "";
for (let char of str) {
if (char == "&") {
newStr += "&";
} else if (char == "<") {
newStr += "<";
} else if (char == ">") {
newStr += ">";
} else if (char == '"') {
newStr += """;
} else if (char == "'") {
newStr += "'";
} 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/
Contributor guide
Assessment
This issue has not been assessed yet.