From 3d21bfe6b94b6214563bbc5a9dc25da241c8e9d8 Mon Sep 17 00:00:00 2001 From: Luca Maraschi Date: Tue, 21 Mar 2017 15:47:25 +0100 Subject: [PATCH] test: invalid chars in http client path This test adds coverage for all the characters which are considered invalid in a http path. PR-URL: https://github.com/nodejs/node/pull/11964 Reviewed-By: Colin Ihrig Reviewed-By: Luigi Pinca Reviewed-By: James M Snell --- test/parallel/test-http-invalid-path-chars.js | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 test/parallel/test-http-invalid-path-chars.js diff --git a/test/parallel/test-http-invalid-path-chars.js b/test/parallel/test-http-invalid-path-chars.js new file mode 100644 index 00000000000000..462e0bc12a0a3f --- /dev/null +++ b/test/parallel/test-http-invalid-path-chars.js @@ -0,0 +1,20 @@ +'use strict'; +const common = require('../common'); +const assert = require('assert'); +const http = require('http'); + +const expectedError = /^TypeError: Request path contains unescaped characters$/; +const theExperimentallyDeterminedNumber = 39; + +function fail(path) { + assert.throws(() => { + http.request({ path }, common.fail); + }, expectedError); +} + +for (let i = 0; i <= theExperimentallyDeterminedNumber; i++) { + const prefix = 'a'.repeat(i); + for (let i = 0; i <= 32; i++) { + fail(prefix + String.fromCodePoint(i)); + } +}