Skip to content

Commit a54c04b

Browse files
Lab csp1: Change from YAML to JavaScript
Signed-off-by: David A. Wheeler <[email protected]>
1 parent f75462f commit a54c04b

File tree

2 files changed

+89
-82
lines changed

2 files changed

+89
-82
lines changed

docs/labs/csp1.html

Lines changed: 1 addition & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
<link rel="stylesheet" href="checker.css">
88
<script src="js-yaml.min.js"></script>
99
<script src="checker.js"></script>
10+
<script src="csp1.js"></script>
1011
<link rel="license" href="https://creativecommons.org/licenses/by/4.0/">
1112

1213
<!-- See create_labs.md for how to create your own lab! -->
@@ -58,88 +59,6 @@
5859
\} \) \) ;
5960
-->
6061

61-
<script id="info" type="application/yaml">
62-
---
63-
hints:
64-
- present: "import"
65-
text: Yes, many JavaScript implementations support an import statement.
66-
However, in this exercise we will use a require form. Please use that
67-
instead.
68-
examples:
69-
- - 'import express from "express";'
70-
- absent: "const"
71-
text: Start with const.
72-
- absent: 'const\s+helmet ='
73-
text: Create a constant name named helmet using the form const helmet = ...
74-
examples:
75-
- - 'const'
76-
- - 'consthelmet = '
77-
- present: 'require \( helmet \)'
78-
text: The parameter of a requirement statement must be string.
79-
Surround the term helment with double-quotes.
80-
examples:
81-
- - ' const helmet = require(helmet);'
82-
- absent: "; $"
83-
text: JavaScript doesn''t require semicolon terminators, but the rest of
84-
the code uses them. You should try to match a coding style when modifying
85-
existing code unless there''s an important reason not to.
86-
Please update the first statment.
87-
examples:
88-
- - ' const helmet = require("helmet")'
89-
- absent: '\s* app \. use \( helmet \( \{'
90-
index: 1
91-
text: Your code should begin with app.use(helmet({
92-
- absent: |
93-
\s* app \. use \( helmet \( \{
94-
contentSecurityPolicy: \{ \s*
95-
index: 1
96-
text: |
97-
Your code should begin with:
98-
app.use(helmet({
99-
contentSecurityPolicy: {
100-
- absent: |
101-
\s* app \. use \( helmet \( \{
102-
contentSecurityPolicy: \{
103-
directives: \{ \s*
104-
index: 1
105-
text: |
106-
Your code should begin with:
107-
app.use(helmet({
108-
contentSecurityPolicy: {
109-
directives: {
110-
- absent: |
111-
\s* app \. use \( helmet \( \{
112-
contentSecurityPolicy: \{
113-
directives: \{
114-
"script-src": \[ "'self'" , ["']https://example.com["'] \] , \s*
115-
index: 1
116-
text: |
117-
Your code should continue with:
118-
app.use(helmet({
119-
contentSecurityPolicy: {
120-
directives: {
121-
"script-src": ["'self'", "https://example.com"],
122-
- absent: |
123-
"style-src": \[ "'self'" \]
124-
index: 1
125-
text: |
126-
Don't forget to include "style-src": ["'self'"]
127-
- absent: '; $'
128-
index: 1
129-
text: JavaScript doesn''t require semicolon terminators, but the rest of
130-
the code uses them. You should try to match a coding style when modifying
131-
existing code unless there''s an important reason not to.
132-
Please update the second statement to use a semicolon terminator.
133-
- absent: |-
134-
\} \} \) \) ; $
135-
index: 1
136-
text: The correct answer is expected to end with `} } ) ) ;` ignoring
137-
whitespace. Check that you have matching parentheses and braces.
138-
- text: I do not have more specific hints to provide. Please ensure that
139-
the parentheses, braces, and brackets pair correctly, as that is
140-
often the problem.
141-
# debug: true
142-
</script>
14362

14463

14564
<!-- More examples:

docs/labs/csp1.js

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
info =
2+
{
3+
hints: [
4+
{
5+
present: "import",
6+
text: "Yes, many JavaScript implementations support an import statement. However, in this exercise we will use a require form. Please use that instead.",
7+
examples: [
8+
[
9+
"import express from \"express\";"
10+
]
11+
]
12+
},
13+
{
14+
absent: "const",
15+
text: "Start with const."
16+
},
17+
{
18+
absent: String.raw`const\s+helmet =`,
19+
text: "Create a constant name named helmet using the form const helmet = ...",
20+
examples: [
21+
[ "const" ],
22+
[ "consthelmet = " ]
23+
]
24+
},
25+
{
26+
present: String.raw`require \( helmet \)`,
27+
text: "The parameter of a requirement statement must be string. Surround the term helment with double-quotes.",
28+
examples: [
29+
[ " const helmet = require(helmet);" ]
30+
]
31+
},
32+
{
33+
absent: "; $",
34+
text: "JavaScript doesn''t require semicolon terminators, but the rest of the code uses them. You should try to match a coding style when modifying existing code unless there''s an important reason not to. Please update the first statment.",
35+
examples: [
36+
[ " const helmet = require(\"helmet\")" ]
37+
]
38+
},
39+
{
40+
absent: String.raw`\s* app \. use \( helmet \( \{`,
41+
index: 1,
42+
text: "Your code should begin with app.use(helmet({"
43+
},
44+
{
45+
absent: String.raw`\s* app \. use \( helmet \( \{
46+
contentSecurityPolicy: \{ \s*
47+
`,
48+
index: 1,
49+
text: "Your code should begin with:\napp.use(helmet({\n contentSecurityPolicy: {\n"
50+
},
51+
{
52+
absent: String.raw`\s* app \. use \( helmet \( \{
53+
contentSecurityPolicy: \{
54+
directives: \{ \s*
55+
`,
56+
index: 1,
57+
text: "Your code should begin with:\napp.use(helmet({\n contentSecurityPolicy: {\n directives: {\n"
58+
},
59+
{
60+
absent: String.raw`\s* app \. use \( helmet \( \{
61+
contentSecurityPolicy: \{
62+
directives: \{
63+
"script-src": \[ "'self'" , ["']https://example.com["'] \] , \s*
64+
`,
65+
index: 1,
66+
text: "Your code should continue with:\napp.use(helmet({\n contentSecurityPolicy: {\n directives: {\n \"script-src\": [\"'self'\", \"https://example.com\"],\n"
67+
},
68+
{
69+
absent: String.raw`"style-src": \[ "'self'" \]
70+
`,
71+
index: 1,
72+
text: "Don't forget to include \"style-src\": [\"'self'\"]\n"
73+
},
74+
{
75+
absent: "; $",
76+
index: 1,
77+
text: "JavaScript doesn''t require semicolon terminators, but the rest of the code uses them. You should try to match a coding style when modifying existing code unless there''s an important reason not to. Please update the second statement to use a semicolon terminator."
78+
},
79+
{
80+
absent: String.raw`\} \} \) \) ; $`,
81+
index: 1,
82+
text: "The correct answer is expected to end with `} } ) ) ;` ignoring whitespace. Check that you have matching parentheses and braces."
83+
},
84+
{
85+
text: "I do not have more specific hints to provide. Please ensure that the parentheses, braces, and brackets pair correctly, as that is often the problem."
86+
}
87+
]
88+
}

0 commit comments

Comments
 (0)