From c20e1b9f597467cca10785ab1f9ef40dcc1bf5a6 Mon Sep 17 00:00:00 2001 From: David D Lowe Date: Tue, 30 May 2017 14:08:16 +0100 Subject: [PATCH 1/3] test: test requests with Unicode in the URL This test currently fails. It illustrates that Unicode in the URL does not arrive intact to the server, there is silent data corruption along the way at some point. This test is for the issue #13296. --- .../test-http-path-contains-unicode.js | 64 +++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 test/parallel/test-http-path-contains-unicode.js diff --git a/test/parallel/test-http-path-contains-unicode.js b/test/parallel/test-http-path-contains-unicode.js new file mode 100644 index 00000000000000..efab6aa1ee5555 --- /dev/null +++ b/test/parallel/test-http-path-contains-unicode.js @@ -0,0 +1,64 @@ +// Copyright Joyent, Inc. and other Node contributors. +// +// Permission is hereby granted, free of charge, to any person obtaining a +// copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to permit +// persons to whom the Software is furnished to do so, subject to the +// following conditions: +// +// The above copyright notice and this permission notice shall be included +// in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN +// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, +// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR +// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE +// USE OR OTHER DEALINGS IN THE SOFTWARE. + + +'use strict'; +require('../common'); +const assert = require('assert'); +const http = require('http'); + +const expected = '/café🐶'; +let result = ''; + +assert.strictEqual( + expected, + '/caf\u{e9}\u{1f436}', + 'Sanity check that string literal produced the expected string' +); + +const server = http.Server(function(req, res) { + result = req.url; + req.on('data', function() { + }).on('end', function() { + server.close(); + res.writeHead(200); + res.end('hello world\n'); + }); + +}); + +server.listen(0, function() { + http.request({ + port: this.address().port, + path: expected, + method: 'GET' + }, function(res) { + console.log(res.statusCode); + res.resume(); + }).on('error', function(e) { + console.log(e.message); + process.exit(1); + }).end(); +}); + +process.on('exit', function() { + assert.strictEqual(expected, result); +}); From 3ba6c866e51af1eb7d9a31fa1a7163912d12aff8 Mon Sep 17 00:00:00 2001 From: David D Lowe Date: Tue, 30 May 2017 15:31:19 +0100 Subject: [PATCH 2/3] test: update style of test --- .../test-http-path-contains-unicode.js | 48 +++++-------------- 1 file changed, 12 insertions(+), 36 deletions(-) diff --git a/test/parallel/test-http-path-contains-unicode.js b/test/parallel/test-http-path-contains-unicode.js index efab6aa1ee5555..b8c010632be3bf 100644 --- a/test/parallel/test-http-path-contains-unicode.js +++ b/test/parallel/test-http-path-contains-unicode.js @@ -1,32 +1,13 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. +'use strict'; +const common = require('../common'); +// This test ensures that Unicode characters in the URL get handled correctly +// by `http` -'use strict'; -require('../common'); const assert = require('assert'); const http = require('http'); const expected = '/café🐶'; -let result = ''; assert.strictEqual( expected, @@ -34,31 +15,26 @@ assert.strictEqual( 'Sanity check that string literal produced the expected string' ); -const server = http.Server(function(req, res) { - result = req.url; - req.on('data', function() { - }).on('end', function() { +const server = http.createServer(common.mustCall(function(req, res) { + assert.strictEqual(req.url, expected); + req.on('data', common.mustCall(function() { + })).on('end', common.mustCall(function() { server.close(); res.writeHead(200); res.end('hello world\n'); - }); + })); -}); +})); server.listen(0, function() { http.request({ port: this.address().port, path: expected, method: 'GET' - }, function(res) { - console.log(res.statusCode); + }, common.mustCall(function(res) { res.resume(); - }).on('error', function(e) { + })).on('error', function(e) { console.log(e.message); process.exit(1); }).end(); }); - -process.on('exit', function() { - assert.strictEqual(expected, result); -}); From 1e4c26b29be100cf49b46c6419087b3aedf0804a Mon Sep 17 00:00:00 2001 From: David D Lowe Date: Tue, 30 May 2017 15:37:07 +0100 Subject: [PATCH 3/3] test: move test to known_issues --- .../{parallel => known_issues}/test-http-path-contains-unicode.js | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename test/{parallel => known_issues}/test-http-path-contains-unicode.js (100%) diff --git a/test/parallel/test-http-path-contains-unicode.js b/test/known_issues/test-http-path-contains-unicode.js similarity index 100% rename from test/parallel/test-http-path-contains-unicode.js rename to test/known_issues/test-http-path-contains-unicode.js