Skip to content

Commit 3091b79

Browse files
Fix other labs to be consistent with input1
This builds on feedback from the OpenSSF education SIG Signed-off-by: David A. Wheeler <[email protected]>
1 parent 325e1a5 commit 3091b79

File tree

5 files changed

+72
-44
lines changed

5 files changed

+72
-44
lines changed

docs/labs/csp1.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -387,8 +387,8 @@ <h2>Task Information</h2>
387387
<h2>Interactive Lab (<span id="grade"></span>)</h2>
388388
<p>
389389
<form id="lab">
390-
<pre><code>
391-
const express = require("express");
390+
<pre><code
391+
>const express = require("express");
392392
<input id="attempt0" type="text" size="60" spellcheck="false" value="const">
393393

394394
const app = express();

docs/labs/hello.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,8 +162,8 @@ <h2>Interactive Lab (<span id="grade"></span>)</h2>
162162
<textarea id="attempt" rows="2" cols="65">...</textarea>
163163
-->
164164
<form id="lab">
165-
<pre><code>
166-
<input id="attempt0" type="text" size="65" spellcheck="false"
165+
<pre><code
166+
><input id="attempt0" type="text" size="60" spellcheck="false"
167167
value='console.log("Goodbye.");'>
168168
</code></pre>
169169
<button type="button" class="hintButton">Hint</button>

docs/labs/input1.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,8 +201,8 @@ <h2>Interactive Lab (<span id="grade"></span>)</h2>
201201
<textarea id="attempt" rows="2" cols="65">...</textarea>
202202
-->
203203
<form id="lab">
204-
<pre></code>
205-
// Set up Express framework and express-validator library
204+
<pre><code
205+
>// Set up Express framework and express-validator library
206206
const express = require("express");
207207
const app = express();
208208
const { query, matchedData, validationResult } =

docs/labs/input2.html

Lines changed: 42 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111

1212
<!-- Sample expected answer -->
1313
<script id="expected0" type="plain/text">
14-
query('id').isLength({max:80}).matches( /^[A-Z]{2}-[0-9]+-[0-9]+$/ ),
14+
query('id').isLength({max:80}).
15+
matches( /^[A-Z]{2}-[0-9]+-[0-9]+$/ ),
1516
</script>
1617

1718
<!-- Full pattern of correct answer.
@@ -78,6 +79,11 @@
7879
text: >
7980
You need to match one or more digits; * allows 0 or more.
8081
A + would be better suited for this task.
82+
- present: |
83+
\s*, , $
84+
text: >
85+
You have two commas at the end. Use only one. You may need to
86+
scroll or increase the text area to see both of them.
8187
successes:
8288
- - query(`id`).isLength( {max:80}).matches(/^[A-Z]{2}-\d+-[0-9]+$/),
8389
- - ' query (`id`) . isLength( {max:80}).matches(/^[A-Z]{2}-\d+-[0-9]+$/ ) , '
@@ -100,9 +106,10 @@ <h1>Lab Exercise input2</h1>
100106
<p>
101107
<h2>Task</h2>
102108
<p>
103-
<b>Please change the code below so the query parameter
104-
<tt>id</tt> <i>must</i> be no longer than 80 characters
105-
and meets this application's part id format requirement.</b>
109+
<b>
110+
Practice validating specialized text input in a program
111+
using a regular expression.
112+
</b>
106113

107114
<p>
108115
<h2>Background</h2>
@@ -150,17 +157,17 @@ <h2>Task Information</h2>
150157
another dash (<tt>-</tt>), and another sequence of one or more digits.
151158

152159
<p>
153-
To do that,
154-
after the first parameter to <tt>app.get</tt>
155-
which says <tt>'/parts'</tt>,
156-
add a new comma-separated parameter.
157-
Start this new parameter with
160+
To do that:
161+
<ol>
162+
<li>After the first parameter to <tt>app.get</tt>
163+
which says <tt>'/parts'</tt>, add a new comma-separated parameter.
164+
<li>Start this new parameter with
158165
<tt>query('id')</tt> to select the
159-
<tt>id</tt> parameter for validation (we've have <i>not</i> filled
166+
<tt>id</tt> parameter for validation (we have <i>not</i> filled
160167
in this part in this lab).
161-
Add a period (<tt>.</tt>) and the validation requirement
168+
<li>Add a period (<tt>.</tt>) and the validation requirement
162169
<tt>isLength()</tt>
163-
The <tt>isLength</tt> method takes, as an optional parameter inside
170+
<li>The <tt>isLength</tt> method takes, as an optional parameter inside
164171
its parentheses,
165172
an object providing specific information such as a minimum and a maximum.
166173
We only want a maximum,
@@ -169,42 +176,55 @@ <h2>Task Information</h2>
169176
Those familiar with JavaScript will know that the "length" value is
170177
the length of the string in UTF-16 code units; that's fine
171178
for our purposes.
179+
</ol>
172180
</p>
173181

174182
<p>
175183
We also need to verify that the input matches our pattern,
176184
which we can verify using a regular expression.
177-
In this situation, we can do this by appending another
178-
period (<tt>.</tt>) and the validation requirement
185+
In this situation, we can do this by:
186+
<ol>
187+
<li>appending another period (<tt>.</tt>) and the validation requirement
179188
<tt>matches()</tt>.
180-
Inside those parenthesis you should supply slash (<tt>/</tt>, the
189+
<li>Inside those parenthesis you should supply slash (<tt>/</tt>, the
181190
text of the regular expression to match, and another slash (<tt>/</tt>).
182191
In JavaScript, a pair of slashes (<tt>/</tt>) surrounds a regular expression.
183-
Remember to match the <i>entire</i> expression
192+
<li>Remember to match the <i>entire</i> expression
184193
(in other words, use <tt>^</tt> and <tt>$</tt>).
185-
Remember, a way to match a single uppercase character is the
186-
pattern <tt>[A-Z]</tt> ... good luck!
194+
<li>Also, remember that a way to match a single uppercase character is the
195+
pattern <tt>[A-Z]</tt>
196+
</ol>
187197

188198
<p>
189199
<h2>Interactive Lab (<span id="grade"></span>)</h2>
190200
<p>
201+
<b>Please change the code below so the query parameter
202+
<tt>id</tt> is only accepted if it's no longer than 80 characters
203+
and meets this application's part id format requirement.
204+
The format is
205+
two uppercase Latin letters (each <tt>A</tt> through <tt>Z</tt>),
206+
then a dash (<tt>-</tt>), a sequence of one or more digits,
207+
another dash (<tt>-</tt>), and another sequence of one or more digits.
208+
</b>
209+
<p>
210+
191211
<!--
192212
You can use this an example for new labs.
193213
For multi-line inputs, instead of <input id="attempt" type="text" ...>, use
194214
<textarea id="attempt" rows="2" cols="65">...</textarea>
195215
-->
196216
<form id="lab">
197-
<pre><code>
198-
// Set up Express framework and express-validator library
217+
<pre><code
218+
>// Set up Express framework and express-validator library
199219
const express = require("express");
200220
const app = express();
201221
const { query, matchedData, validationResult } =
202222
require('express-validator');
203223

204224
// Implement requests, e.g., http://localhost:3000/parts?id=1
205225
app.get('/parts',
206-
<input id="attempt0" type="text" size="65" spellcheck="false"
207-
value=" ,">
226+
<textarea id="attempt0" rows="2" cols="64" spellcheck="false">
227+
,</textarea>
208228
(req, res) =&gt; { // Execute this code if /invoices seen
209229
const result = validationResult(req); // Retrieve errors
210230
if (result.isEmpty()) { // No errors

docs/labs/regex1.html

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,13 @@
8888
<script id="info" type="application/yaml">
8989
---
9090
hints:
91+
- present: |-
92+
/
93+
text: In JavaScript a constant regular expression is surrounded by
94+
forward slashes like /PATTERN/. However, for this exercise we only
95+
want the text inside the slashes (the pattern itself).
96+
examples:
97+
- - "/"
9198
- absent: |-
9299
^\^
93100
text: For input validation, start with '^' to indicate a full match.
@@ -249,10 +256,9 @@ <h1>Lab Exercise regex1</h1>
249256
the labs</a>.
250257

251258
<p>
252-
<h2>Task</h2>
259+
<h2>Goal</h2>
253260
<p>
254-
<b>Please create various regular expression (regex) patterns
255-
that meet the criteria below.</b>
261+
<b>Learn how to create simple regular expressions.</b>
256262

257263
<p>
258264
<h2>Background</h2>
@@ -262,8 +268,6 @@ <h2>Background</h2>
262268
Regexes can be used to validate input; when used correctly,
263269
they can counter many attacks.
264270

265-
<p>
266-
<h2>Task Information</h2>
267271
<p>
268272
Different regex languages have slightly different notations,
269273
but they have much in common. Here are some basic rules for regex
@@ -294,6 +298,8 @@ <h2>Task Information</h2>
294298
So for example, "<tt>(yes|no)</tt>" is a way to match either "yes" or "no".
295299
</ol>
296300

301+
<p>
302+
<h2>Task Information</h2>
297303
<p>
298304
We want to use regexes to <i>validate</i> input.
299305
That is, the input should <i>completely</i> match the regex pattern.
@@ -344,6 +350,9 @@ <h2>Task Information</h2>
344350
<p>
345351
<h2>Interactive Lab (<span id="grade"></span>)</h2>
346352

353+
<b>Please create regular expression (regex) patterns
354+
that meet the criteria below.</b>
355+
347356
<h3>Part 1</h2>
348357
<p>
349358
Create a regular expression, for use in ECMAScript (JavaScript),
@@ -353,9 +362,8 @@ <h3>Part 1</h2>
353362
For multi-line inputs, instead of <input id="attempt0" type="text" ...>, use
354363
<textarea id="attempt" rows="2" cols="65">...</textarea>
355364
-->
356-
<form id="lab1">
357-
<pre></code>
358-
<input id="attempt0" type="text" size="60" spellcheck="false" value="">
365+
<form id="lab1"><pre><code
366+
><input id="attempt0" type="text" size="60" spellcheck="false" value="">
359367
</code></pre>
360368
<button type="button" class="hintButton">Hint</button>
361369
<button type="button" class="resetButton">Reset</button>
@@ -372,8 +380,8 @@ <h3>Part 2</h2>
372380
<textarea id="attempt" rows="2" cols="65">...</textarea>
373381
-->
374382
<form id="lab2">
375-
<pre></code>
376-
<input id="attempt1" type="text" size="60" spellcheck="false" value="">
383+
<pre><code
384+
><input id="attempt1" type="text" size="60" spellcheck="false" value="">
377385
</code></pre>
378386
<button type="button" class="hintButton">Hint</button>
379387
<button type="button" class="resetButton">Reset</button>
@@ -390,8 +398,8 @@ <h3>Part 3</h2>
390398
<textarea id="attempt" rows="2" cols="65">...</textarea>
391399
-->
392400
<form id="lab3">
393-
<pre></code>
394-
<input id="attempt2" type="text" size="60" spellcheck="false" value="">
401+
<pre><code
402+
><input id="attempt2" type="text" size="60" spellcheck="false" value="">
395403
</code></pre>
396404
<button type="button" class="hintButton">Hint</button>
397405
<button type="button" class="resetButton">Reset</button>
@@ -409,8 +417,8 @@ <h3>Part 4</h2>
409417
<textarea id="attempt" rows="2" cols="65">...</textarea>
410418
-->
411419
<form id="lab4">
412-
<pre></code>
413-
<input id="attempt3" type="text" size="60" spellcheck="false" value="">
420+
<pre><code
421+
><input id="attempt3" type="text" size="60" spellcheck="false" value="">
414422
</code></pre>
415423
<button type="button" class="hintButton">Hint</button>
416424
<button type="button" class="resetButton">Reset</button>
@@ -429,8 +437,8 @@ <h3>Part 5</h2>
429437
<textarea id="attempt" rows="2" cols="65">...</textarea>
430438
-->
431439
<form id="lab5">
432-
<pre></code>
433-
<input id="attempt4" type="text" size="60" spellcheck="false" value="">
440+
<pre><code
441+
><input id="attempt4" type="text" size="60" spellcheck="false" value="">
434442
</code></pre>
435443
<button type="button" class="hintButton">Hint</button>
436444
<button type="button" class="resetButton">Reset</button>

0 commit comments

Comments
 (0)