File tree Expand file tree Collapse file tree 2 files changed +20
-0
lines changed
Expand file tree Collapse file tree 2 files changed +20
-0
lines changed Original file line number Diff line number Diff line change @@ -59,6 +59,10 @@ exports.querystringStringify = function (obj) {
5959 var saved = querystring . escape
6060 querystring . escape = escape // global
6161 var ret = querystring . stringify ( obj )
62+ ret = ret . replace ( / [ \@ \* \/ \+ ] / g, function ( char ) {
63+ // `escape` doesn't encode the characters @*/+ so we do it manually
64+ return '%' + char . charCodeAt ( 0 ) . toString ( 16 ) . toUpperCase ( )
65+ } )
6266 querystring . escape = saved
6367 return ret
6468}
Original file line number Diff line number Diff line change 1+ var common = require ( '../lib/common' )
2+ var test = require ( 'tape' )
3+
4+ // https://github.com/feross/webtorrent/issues/196
5+ test ( 'encode special chars +* in http tracker urls' , function ( t ) {
6+ var q = {
7+ info_hash : new Buffer ( 'a2a15537542b22925ad10486bf7a8b2a9c42f0d1' , 'hex' ) . toString ( 'binary' )
8+ }
9+ var encoded = 'info_hash=%A2%A1U7T%2B%22%92Z%D1%04%86%BFz%8B%2A%9CB%F0%D1'
10+ t . equal ( common . querystringStringify ( q ) , encoded )
11+
12+ // sanity check that encode-decode matches up
13+ t . deepEqual ( common . querystringParse ( common . querystringStringify ( q ) ) , q )
14+
15+ t . end ( )
16+ } )
You can’t perform that action at this time.
0 commit comments