|
22 | 22 | var common = require('../common');
|
23 | 23 | var assert = require('assert');
|
24 | 24 | var http = require('http');
|
25 |
| -var util = require('util'); |
26 | 25 |
|
27 |
| -first(); |
28 |
| - |
29 |
| -function first() { |
30 |
| - test('/~username/', '/~username/', second); |
31 |
| -} |
32 |
| -function second() { |
33 |
| - test('/\'foo bar\'', '/%27foo%20bar%27', third); |
34 |
| -} |
35 |
| -function third() { |
36 |
| - var expected = '/%3C%3E%22%60%20%0D%0A%09%7B%7D%7C%5C%5E~%60%27'; |
37 |
| - test('/<>"` \r\n\t{}|\\^~`\'', expected); |
38 |
| -} |
39 |
| - |
40 |
| -function test(path, expected, next) { |
41 |
| - function helper(arg, next) { |
42 |
| - var server = http.createServer(function(req, res) { |
43 |
| - assert.equal(req.url, expected); |
44 |
| - res.end('OK'); |
45 |
| - server.close(next); |
46 |
| - }); |
47 |
| - server.on('clientError', function(err) { |
48 |
| - throw err; |
49 |
| - }); |
50 |
| - server.listen(common.PORT, '127.0.0.1', function() { |
51 |
| - http.get(arg); |
52 |
| - }); |
53 |
| - } |
54 |
| - |
55 |
| - // Go the extra mile to ensure that the behavior of |
56 |
| - // http.get("http://example.com/...") matches http.get({ path: ... }). |
57 |
| - test1(); |
58 |
| - |
59 |
| - function test1() { |
60 |
| - console.log('as url: ' + util.inspect(path)); |
61 |
| - helper('http://127.0.0.1:' + common.PORT + path, test2); |
62 |
| - } |
63 |
| - function test2() { |
64 |
| - var options = { |
65 |
| - host: '127.0.0.1', |
66 |
| - port: common.PORT, |
67 |
| - path: path |
68 |
| - }; |
69 |
| - console.log('as options: ' + util.inspect(options)); |
70 |
| - helper(options, done); |
71 |
| - } |
72 |
| - function done() { |
73 |
| - if (next) next(); |
74 |
| - } |
75 |
| -} |
| 26 | +assert.throws(function() { |
| 27 | + // Path with spaces in it should throw. |
| 28 | + http.get({ path: 'bad path' }, assert.fail); |
| 29 | +}, /contains unescaped characters/); |
0 commit comments