File tree Expand file tree Collapse file tree 2 files changed +27
-0
lines changed Expand file tree Collapse file tree 2 files changed +27
-0
lines changed Original file line number Diff line number Diff line change @@ -122,6 +122,11 @@ function SocketRest() {
122122
123123 // Fire route function
124124 if ( resourceMatch ) {
125+ // Decode params
126+ for ( let prop in resourceMatch ) {
127+ resourceMatch [ prop ] = decodeURIComponent ( resourceMatch [ prop ] ) ;
128+ }
129+
125130 // Create request information holder
126131 var req = {
127132 query : route . query ,
Original file line number Diff line number Diff line change @@ -143,4 +143,26 @@ describe('#socket-rest', function() {
143143 } ) ;
144144 } ) ;
145145 } ) ;
146+
147+ describe ( 'Encoded parameters' , function ( ) {
148+ var strangeParam = 'some:strange string with _ spaces=" and stuff' ;
149+
150+ // Register get route
151+ socketRest . get ( '/books/:bookName' , function ( req , socket , callback ) {
152+ expect ( req . params . bookName ) . to . equal ( strangeParam ) ;
153+
154+ callback ( ) ;
155+ } ) ;
156+
157+ it ( 'should handle encoded params' , function ( done ) {
158+ // Connect client and request route
159+ var client = ioc . connect ( socketURL ) ;
160+
161+ client . on ( 'connect' , function ( ) {
162+ client . emit ( '/books/' + encodeURIComponent ( strangeParam ) + '/get' , function ( ) {
163+ done ( ) ;
164+ } ) ;
165+ } ) ;
166+ } ) ;
167+ } ) ;
146168} ) ;
You can’t perform that action at this time.
0 commit comments