Skip to content

Commit 6b9308e

Browse files
vsemozhetbytbevacqua
authored andcommitted
ch02: fix typos in tagged templates examples (#58)
1 parent d0cc544 commit 6b9308e

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

ch02.asciidoc

+2-2
Original file line numberDiff line numberDiff line change
@@ -1185,7 +1185,7 @@ var name = 'Maurice'
11851185
var emotion = 'thrilled'
11861186
var text = tag`Hello, ${ name }. I am ${ emotion } to meet you!`
11871187
console.log(text)
1188-
// <- 'Hello Maurice, I am thrilled to meet you!'
1188+
// <- 'Hello, Maurice. I am thrilled to meet you!'
11891189
----
11901190

11911191
Multiple use cases apply to tagged templates. One possible use case might be to make user input uppercase, making the string sound satirical. That's what the following piece of code does. We've modified `tag` slightly so that any interpolated strings are uppercased.
@@ -1200,7 +1200,7 @@ function upper(parts, ...values) {
12001200
var name = 'Maurice'
12011201
var emotion = 'thrilled'
12021202
upper`Hello, ${ name }. I am ${ emotion } to meet you!`
1203-
// <- 'Hello MAURICE, I am THRILLED to meet you!'
1203+
// <- 'Hello, MAURICE. I am THRILLED to meet you!'
12041204
----
12051205

12061206
A decidedly more useful use case would be to sanitize expressions interpolated into your templates, automatically, using a tagged template. Given a template where all expressions are considered user input, we could use a hypothetical `sanitize` library to remove HTML tags and similar hazards, preventing cross-site scripting (XSS) attacks where users might inject malicious HTML into our websites.

0 commit comments

Comments
 (0)