You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
npm run test:sanitize
> test:sanitize
> node test/sanitization.test.js
POST /
GET /
✖ POST with script tag is correctly sanitized (117.702346ms)
AssertionError [ERR_ASSERTION]: Expected <script> to have '<' replaced with '<', but received:
<!doctype html><html><head><title>All posts</title><meta name="viewport" content="width=device-width, initial-scale=1"></head><body><h2>New post</h2><form method="POST"><p><label for="nickname">Nickname</label><input id="nickname" name="nickname"></p><p><label for="message">Message</label><textarea id="message" name="message"></textarea></p><button>Send</button></form><h2>All posts</h2><ul><li><p><script>alert('uh oh')</script></p><p>—oli | 18/04/2024, 21:50:16</p></li></ul></body></html>
at TestContext.<anonymous> (/Users/jasonwarren/Code/FAC/FAC-Challenge-Sanitize/test/sanitization.test.js:12:10)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async Test.run (node:internal/test_runner/test:548:9)
at async startSubtest (node:internal/test_runner/harness:190:3) {
generatedMessage: false,
code: 'ERR_ASSERTION',
actual: '\n <!doctype html>\n <html>\n <head>\n <title>All posts</title>\n <meta name="viewport" content="width=device-width, initial-scale=1">\n </head>\n <body>\n \n <h2>New post</h2>\n...',
expected: /<script>alert\('uh oh'\)<\/script>/i,
operator: 'match'
}
ℹ tests 1
ℹ pass 0
ℹ fail 1
ℹ cancelled 0
ℹ skipped 0
ℹ todo 0
ℹ duration_ms 221.632316
Success Example
functionsanitize(dirty){//removed other charactersconstclean=dirty.replace(/[<]/g,switch(match){case'<':
return'<';// case '>':// return '>';// case '&':// return '&';// case "'":// return ''';// case '"':// return '"';}});returnclean;}
The text was updated successfully, but these errors were encountered:
Current Behaviour
The sanitize test will fail if the characters
>&'"
are cleaned, and requires only replacing<
.Fail Example
Code
Error Message
Success Example
The text was updated successfully, but these errors were encountered: