Skip to content

Commit 29a9b44

Browse files
Merge pull request #759 from ossf/input2_answers
Lab input2: Move answers to JavaScript
2 parents aa59cc5 + 87cc3cf commit 29a9b44

File tree

2 files changed

+25
-29
lines changed

2 files changed

+25
-29
lines changed

docs/labs/input2.html

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -10,30 +10,6 @@
1010
<script src="input2.js"></script>
1111
<link rel="license" href="https://creativecommons.org/licenses/by/4.0/">
1212

13-
<!-- Sample expected answer -->
14-
<script id="expected0" type="plain/text">
15-
query('id').isLength({max:80}).
16-
matches( /^[A-Z]{2}-[0-9]+-[0-9]+$/ ),
17-
</script>
18-
19-
<!-- Full pattern of correct answer.
20-
This specific example is a worst case; we're using
21-
using regex to check on a regex, requiring a large number of escapes.
22-
This pattern is very generous, allowing
23-
constructs like \d for digits and {1,} instead of +. -->
24-
<script id="correct0" type="plain/text">
25-
\s* query \( ('id'|"id"|`id`) \)
26-
\. isLength \( \{ max: 80 ,? \} \)
27-
\. matches \(
28-
\/\^
29-
\[A-Z\](\{2\}|\[A-Z\])
30-
-
31-
(\[0-9\]|\\d)(\+|\{1,\})
32-
-
33-
(\[0-9\]|\\d)(\+|\{1,\})\$\/
34-
\) , \s*
35-
</script>
36-
3713
</head>
3814
<body>
3915
<!-- For GitHub Pages formatting: -->

docs/labs/input2.js

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ info =
1515
},
1616
{
1717
present: "(islength|Islength|IsLength|ISLENGTH)",
18-
text: "JavaScript is case-sensitive. Use isLength instead of the case you have.\n"
18+
text: "JavaScript is case-sensitive. Use isLength instead of the case you have."
1919
},
2020
{
2121
absent: "isLength",
@@ -47,13 +47,30 @@ info =
4747
},
4848
{
4949
present: String.raw`matches \( /.*(\[0-9\]|\d)\*`,
50-
text: "You need to match one or more digits; * allows 0 or more. A + would be better suited for this task.\n"
50+
text: "You need to match one or more digits; * allows 0 or more. A + would be better suited for this task."
5151
},
5252
{
5353
present: String.raw`\s*, , $`,
54-
text: "You have two commas at the end. Use only one. You may need to scroll or increase the text area to see both of them.\n"
54+
text: "You have two commas at the end. Use only one. You may need to scroll or increase the text area to see both of them."
5555
}
5656
],
57+
expected: [
58+
String.raw` query('id').isLength({max:80}).
59+
matches( /^[A-Z]{2}-[0-9]+-[0-9]+$/ ),`,
60+
],
61+
// Full pattern of correct answer.
62+
// This specific example is a worst case; we're using
63+
// a regex to check on a regex, requiring a large number of escapes.
64+
correct: [
65+
// This pattern is very generous, allowing
66+
// constructs like \d for digits and {1,} instead of +.
67+
String.raw`\s*
68+
query \( ('id'|"id"|${BACKQUOTE}id${BACKQUOTE}) \)
69+
\. isLength \( \{ max: 80 ,? \} \)
70+
\. matches \(
71+
\/\^\[A-Z\](\{2\}|\[A-Z\])-(\[0-9\]|\\d)(\+|\{1,\})-(\[0-9\]|\\d)(\+|\{1,\})\$\/
72+
\) , \s*`
73+
],
5774
successes: [
5875
[
5976
"query(`id`).isLength( {max:80}).matches(/^[A-Z]{2}-\\d+-[0-9]+$/),"
@@ -74,6 +91,9 @@ info =
7491
],
7592
[
7693
"query(`id`).isLength( {max:80}).matches(/^[A-Z]{2}-\\d+-[0-9]+$/)"
77-
]
78-
]
94+
],
95+
[
96+
"query(`id`).isLength( {max:80}).matches(/^[A-Z]{2}- \\d+-[0-9]+$/),"
97+
],
98+
],
7999
}

0 commit comments

Comments
 (0)