Commit 14489548 authored by Sindre Sorhus's avatar Sindre Sorhus

Merge pull request #398 from passy/dart-escaping

dart: Escape HTML in todo rendering
parents 5b9773d4 d9734935
......@@ -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;");
}
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
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