From 45becee133f401bf3f2617e2010c7709bf224691 Mon Sep 17 00:00:00 2001 From: Natalie Weizenbaum Date: Mon, 17 Oct 2016 17:56:39 -0700 Subject: [PATCH] Escape ASCII non-printable string contents. --- lib/src/visitor/serialize.dart | 33 +++++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/lib/src/visitor/serialize.dart b/lib/src/visitor/serialize.dart index b1ac1d76..5d691321 100644 --- a/lib/src/visitor/serialize.dart +++ b/lib/src/visitor/serialize.dart @@ -526,11 +526,40 @@ class _SerializeCssVisitor } break; - case $cr: + // Write newline characters and unprintable ASCII characters as escapes. + case $nul: + case $soh: + case $stx: + case $etx: + case $eot: + case $enq: + case $ack: + case $bel: case $lf: + case $vt: case $ff: + case $cr: + case $so: + case $si: + case $dle: + case $dc1: + case $dc2: + case $dc3: + case $dc4: + case $nak: + case $syn: + case $etb: + case $can: + case $em: + case $sub: + case $esc: + case $fs: + case $gs: + case $rs: + case $us: buffer.writeCharCode($backslash); - buffer.writeCharCode(hexCharFor(char)); + if (char > 0xF) buffer.writeCharCode(hexCharFor(char >> 4)); + buffer.writeCharCode(hexCharFor(char & 0xF)); if (string.length == i + 1) break; var next = string.codeUnitAt(i + 1);