Commit 3abb0607 authored by Pascal Hartig's avatar Pascal Hartig

dart: Escape HTML in todo rendering

parent eec36343
......@@ -13,10 +13,10 @@ class TodoWidget {
<li ${todo.completed ? 'class="completed"' : ''}>
<div class='view'>
<input class='toggle' type='checkbox' ${todo.completed ? 'checked' : ''}>
<label class='todo-content'>${todo.title}</label>
<label class='todo-content'>${htmlEscape(todo.title)}</label>
<button class='destroy'></button>
</div>
<input class='edit' value='${todo.title}'>
<input class='edit' value='${htmlEscape(todo.title)}'>
</li>
''');
......
......@@ -40,3 +40,16 @@ class UUID {
return random.nextInt(65536).toRadixString(16);
}
}
/**
* Escapes HTML-special characters of [text] so that the result can be
* included verbatim in HTML source code, either in an element body or in an
* attribute value.
*/
String htmlEscape(String text) {
return text.replaceAll("&", "&amp;")
.replaceAll("<", "&lt;")
.replaceAll(">", "&gt;")
.replaceAll('"', "&quot;")
.replaceAll("'", "&apos;");
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment