mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-05-13 22:52:52 +00:00
LibHTML+IRCClient: Add an escape_html_entities() helper
This simple helper escapes '<', '>' and '&' so they can be used in HTML text without interfering with the parser. Use this in IRCClient to prevent incoming messages from messing with the DOM :^)
This commit is contained in:
parent
d17930d9e2
commit
a377e8d3f5
Notes:
sideshowbarker
2024-07-19 11:20:30 +09:00
Author: https://github.com/awesomekling
Commit: a377e8d3f5
3 changed files with 19 additions and 2 deletions
|
@ -339,3 +339,19 @@ RefPtr<Document> parse_html_document(const StringView& html, const URL& url)
|
|||
|
||||
return document;
|
||||
}
|
||||
|
||||
String escape_html_entities(const StringView& html)
|
||||
{
|
||||
StringBuilder builder;
|
||||
for (int i = 0; i < html.length(); ++i) {
|
||||
if (html[i] == '<')
|
||||
builder.append("<");
|
||||
else if (html[i] == '>')
|
||||
builder.append(">");
|
||||
else if (html[i] == '&')
|
||||
builder.append("&");
|
||||
else
|
||||
builder.append(html[i]);
|
||||
}
|
||||
return builder.to_string();
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue