Skip to content

Commit 2d3bf10

Browse files
committed
Adds parameters decoding
1 parent be1b6ab commit 2d3bf10

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

index.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff 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,

test/test.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff 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
});

0 commit comments

Comments
 (0)