|
| 1 | +// Copyright Joyent, Inc. and other Node contributors. |
| 2 | +// |
| 3 | +// Permission is hereby granted, free of charge, to any person obtaining a |
| 4 | +// copy of this software and associated documentation files (the |
| 5 | +// "Software"), to deal in the Software without restriction, including |
| 6 | +// without limitation the rights to use, copy, modify, merge, publish, |
| 7 | +// distribute, sublicense, and/or sell copies of the Software, and to permit |
| 8 | +// persons to whom the Software is furnished to do so, subject to the |
| 9 | +// following conditions: |
| 10 | +// |
| 11 | +// The above copyright notice and this permission notice shall be included |
| 12 | +// in all copies or substantial portions of the Software. |
| 13 | +// |
| 14 | +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
| 15 | +// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
| 16 | +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN |
| 17 | +// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, |
| 18 | +// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR |
| 19 | +// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE |
| 20 | +// USE OR OTHER DEALINGS IN THE SOFTWARE. |
| 21 | + |
| 22 | +var common = require('../common'); |
| 23 | +var assert = require('assert'); |
| 24 | +var http = require('http'); |
| 25 | + |
| 26 | +first(); |
| 27 | + |
| 28 | +function first() { |
| 29 | + test('/~username/', '/~username/', second); |
| 30 | +} |
| 31 | +function second() { |
| 32 | + test('/\'foo bar\'', '/%27foo%20bar%27', third); |
| 33 | +} |
| 34 | +function third() { |
| 35 | + var expected = '/%3C%3E%22%60%20%0D%0A%09%7B%7D%7C%5C%5E~%60%27'; |
| 36 | + test('/<>"` \r\n\t{}|\\^~`\'', expected); |
| 37 | +} |
| 38 | + |
| 39 | +function test(path, expected, next) { |
| 40 | + var server = http.createServer(function(req, res) { |
| 41 | + assert.equal(req.url, expected); |
| 42 | + res.end('OK'); |
| 43 | + server.close(function() { |
| 44 | + if (next) next(); |
| 45 | + }); |
| 46 | + }); |
| 47 | + server.on('clientError', function(err) { |
| 48 | + throw err; |
| 49 | + }); |
| 50 | + var options = { |
| 51 | + host: '127.0.0.1', |
| 52 | + port: common.PORT, |
| 53 | + path: path |
| 54 | + }; |
| 55 | + server.listen(options.port, options.host, function() { |
| 56 | + http.get(options); |
| 57 | + }); |
| 58 | +} |
0 commit comments