Skip to content

Commit 1d0895c

Browse files
Lab hardcoded: remove YAML
Signed-off-by: David A. Wheeler <[email protected]>
1 parent c0bab11 commit 1d0895c

File tree

2 files changed

+60
-68
lines changed

2 files changed

+60
-68
lines changed

docs/labs/hardcoded.html

Lines changed: 1 addition & 68 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="hardcoded.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! -->
@@ -24,74 +25,6 @@
2425
System \. getenv \( "PASSWORD" \) \) \; \s*
2526
</script>
2627

27-
<script id="info" type="application/yaml">
28-
---
29-
hints:
30-
- absent: |
31-
^ \s* conn = DriverManager \. getConnection \( url \,
32-
text: >
33-
Your answer should start with
34-
`conn = DriverManager.getConnection( url,`
35-
just as the initial value did. You might want to use the `Reset` button.
36-
- absent: |
37-
System \. getenv
38-
text: >
39-
Use `System.getenv` to retrieve an environment variable value.
40-
For example, use `System.getenv("USERNAME")` to retrieve the username.
41-
- present: |
42-
System \. getenv \( \"admin\" \)
43-
text: >
44-
You need to pass to
45-
`System.getenv` the name of an environment variable value, not the
46-
result you might get.
47-
Do not use constructs like `System.getenv("admin")`.
48-
Instead, for example,
49-
use `System.getenv("USERNAME")` to retrieve the username.
50-
- absent: |
51-
System \. getenv \( \"PASSWORD\" \)
52-
text: >
53-
Use `System.getenv` to retrieve an environment variable value.
54-
For example, use `System.getenv("USERNAME")` to retrieve the username.
55-
- present: "admin"
56-
text: >
57-
The term 'admin' should not be in your code.
58-
You should be retrieving both the username and the password
59-
from somewhere else, in this case, from environment variables.
60-
- present: |
61-
(system|Getenv|GetEnv)
62-
text: >
63-
Java is case-sensitive. You need to use
64-
`System.getenv` and not some other variation of uppercase or lowercase.
65-
- absent: |-
66-
\; \s* $
67-
text: >
68-
Java statements must end with a semicolon.
69-
- absent: |
70-
\) \) \; \s* $
71-
text: >
72-
Double-check your closing parentheses at the end of the statement.
73-
- present: |
74-
new\s+String
75-
text: >
76-
You do not need to construct a new string to retrieve an
77-
environment variable value.
78-
- present: |
79-
^ conn = DriverManager \. getConnection \( url \) \; \s* $
80-
text: >
81-
In some sense this is correct, as long as the url is not hardcoded.
82-
However, it's often better if administrators can easily change the
83-
username or password separately, and it makes out point clearer.
84-
Please provide the username and password and separate values.
85-
- present: |
86-
^ \s* conn = DriverManager \. getConnection \( url \,
87-
System \. getenv \( "PASSWORD" \) \,
88-
System \. getenv \( "USERNAME" \) \) \; \s* $
89-
text: >
90-
The order of parameters is wrong. Provide the url, then the username,
91-
then the password. You're providing the url, then the password, then
92-
the username, which swaps the second and third parameters.
93-
# debug: true
94-
</script>
9528
</head>
9629
<body>
9730
<!-- For GitHub Pages formatting: -->

docs/labs/hardcoded.js

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
info =
2+
{
3+
hints: [
4+
{
5+
absent: String.raw`^ \s* conn = DriverManager \. getConnection \( url \,
6+
`,
7+
text: "Your answer should start with `conn = DriverManager.getConnection( url,` just as the initial value did. You might want to use the `Reset` button.\n"
8+
},
9+
{
10+
absent: String.raw`System \. getenv
11+
`,
12+
text: "Use `System.getenv` to retrieve an environment variable value. For example, use `System.getenv(\"USERNAME\")` to retrieve the username.\n"
13+
},
14+
{
15+
present: String.raw`System \. getenv \( \"admin\" \)
16+
`,
17+
text: "You need to pass to `System.getenv` the name of an environment variable value, not the result you might get. Do not use constructs like `System.getenv(\"admin\")`. Instead, for example, use `System.getenv(\"USERNAME\")` to retrieve the username.\n"
18+
},
19+
{
20+
absent: String.raw`System \. getenv \( \"PASSWORD\" \)
21+
`,
22+
text: "Use `System.getenv` to retrieve an environment variable value. For example, use `System.getenv(\"USERNAME\")` to retrieve the username.\n"
23+
},
24+
{
25+
present: "admin",
26+
text: "The term 'admin' should not be in your code. You should be retrieving both the username and the password from somewhere else, in this case, from environment variables.\n"
27+
},
28+
{
29+
present: "(system|Getenv|GetEnv)\n",
30+
text: "Java is case-sensitive. You need to use `System.getenv` and not some other variation of uppercase or lowercase.\n"
31+
},
32+
{
33+
absent: String.raw`\; \s* $`,
34+
text: "Java statements must end with a semicolon.\n"
35+
},
36+
{
37+
absent: String.raw`\) \) \; \s* $
38+
`,
39+
text: "Double-check your closing parentheses at the end of the statement.\n"
40+
},
41+
{
42+
present: String.raw`new\s+String
43+
`,
44+
text: "You do not need to construct a new string to retrieve an environment variable value.\n"
45+
},
46+
{
47+
present: String.raw`^ conn = DriverManager \. getConnection \( url \) \; \s* $
48+
`,
49+
text: "In some sense this is correct, as long as the url is not hardcoded. However, it's often better if administrators can easily change the username or password separately, and it makes out point clearer. Please provide the username and password and separate values.\n"
50+
},
51+
{
52+
present: String.raw`^ \s* conn = DriverManager \. getConnection \( url \,
53+
System \. getenv \( "PASSWORD" \) \,
54+
System \. getenv \( "USERNAME" \) \) \; \s* $
55+
`,
56+
text: "The order of parameters is wrong. Provide the url, then the username, then the password. You're providing the url, then the password, then the username, which swaps the second and third parameters.\n"
57+
}
58+
]
59+
}

0 commit comments

Comments
 (0)