Sanitize user input: Difference between revisions
→{{header|Wren}}: Tightened up rules for acceptable names in line with revised task requirements.
m (→{{header|Phix}}: or whitelist as per Raku) |
(→{{header|Wren}}: Tightened up rules for acceptable names in line with revised task requirements.) |
||
Line 82:
{{libheader|Wren-trait}}
<br>
The following assumes that names are only valid if they contain ASCII letters, hyphens or apostrophes. However, the first or last character of a name can't be a punctuation character and a name must be between 1 and 20 characters long. A single character name is allowed to cater for an initial where the full name is not known. People are given a chance to abbreviate their names if they are too long.
No other characters are allowed including control characters, spaces, symbols, emojis and non-English letters. Names which include them are simply rejected.
Furthermore,
<lang ecmascript>import "/ioutil" for Input
import "/pattern" for Pattern
Line 108:
"drop", "delete", "erase", "kill", "wipe", "remove",
"file", "files", "directory", "directories",
"table", "tables", "record", "records", "database", "databases",
"system", "system32", "system64", "rm", "rf", "rmdir", "format", "reformat"
]
var p = Pattern.new("+1&y", Pattern.whole)▼
var i = Pattern.letter + punct
▲var punct = "'-_\xad" // allowable punctuation
var sanitizeInput = Fn.new { |name|
Line 144 ⟶ 146:
{{out}}
Sample (abridged) input/output
<pre>
Enter your first name :
Enter your last name : Duck▼
Enter your first name : Mickey Mouse▼
Sorry, your name contains unacceptable characters.
Line 157 ⟶ 156:
Enter your first name : Fred
Enter your last name : rm -rf
Sorry, your name contains unacceptable characters.
Line 164 ⟶ 163:
Sorry, your name is unacceptable.
Enter your first name :
Sorry, your name contains unacceptable characters.
Enter your last name : Pépé▼
Enter your first name :
Sorry, your name contains unacceptable characters.
Enter your last name : Monroe▼
Enter your first name :
Sorry, your name contains unacceptable characters.
Enter your last name : O'Riley▼
Enter your first name :
Sorry, your name contains unacceptable characters.
Enter your first name : Don ald
Sorry, your name contains unacceptable characters.
Enter your last name : Schäfer
Sorry, your name contains unacceptable characters.
Line 179 ⟶ 185:
Enter your last name : Wolfeschlegelsteinhausenbergerdorff
Must have a length between 1 and 20 characters, try again.
Enter your last name : Wolfeschlegelstein'
... (plus another
The following
Marilyn Monroe
Bridget O'Riley
▲Blaine Wolfeschlegelstein'h
▲... (10 more)
</pre>
|