Skip to content

Commit d2756c6

Browse files
committed
merged
2 parents faadafb + d1b2c42 commit d2756c6

File tree

2 files changed

+47
-1
lines changed

2 files changed

+47
-1
lines changed

lib/types/operation.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -512,7 +512,9 @@ Operation.prototype.urlify = function (args, maskPasswords) {
512512
if (Array.isArray(value)) {
513513
value = this.encodePathCollection(param.collectionFormat, param.name, value, isPassword);
514514
} else {
515-
value = this.encodePathParam(value, isPassword);
515+
if((typeof(param['x-escape']) === 'undefined') || (param['x-escape'] === true)) {
516+
value = this.encodePathParam(value, isPassword);
517+
}
516518
}
517519

518520
requestUrl = requestUrl.replace(reg, value);

test/operation.js

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,50 @@ describe('operations', function () {
269269
expect(url).toBe('http://localhost/foo/tony%20tam/bar');
270270
});
271271

272+
it('should generate a url with path param with proper escaping, ignoring slashes if told to do so', function () {
273+
var parameters = [
274+
{
275+
in: 'path',
276+
name: 'location',
277+
type: 'string',
278+
'x-escape': false
279+
}
280+
];
281+
var op = new Operation({}, 'http', 'test', 'get', '/foo/{location}', { parameters: parameters },
282+
{}, {}, new auth.SwaggerAuthorizations());
283+
var url = op.urlify({
284+
location: 'qux/baz.txt'
285+
});
286+
287+
expect(url).toBe('http://localhost/foo/qux/baz.txt');
288+
});
289+
290+
it('should generate a url with path param with proper escaping, ignoring slashes if told to do so, with multiple slashes', function () {
291+
var parameters = [
292+
{
293+
in: 'path',
294+
name: 'type',
295+
type: 'string',
296+
'x-escape': false
297+
},
298+
{
299+
in: 'path',
300+
name: 'location',
301+
type: 'string',
302+
'x-escape': false
303+
}
304+
];
305+
var op = new Operation({}, 'http', 'test', 'get', '/foo/{type}/{location}', { parameters: parameters },
306+
{}, {}, new auth.SwaggerAuthorizations());
307+
var url = op.urlify({
308+
type: 'bar/bar',
309+
location: 'qux/baz.txt'
310+
});
311+
312+
expect(url).toBe('http://localhost/foo/bar/bar/qux/baz.txt');
313+
});
314+
315+
272316
it('should generate a url with path param string array', function () {
273317
var parameters = [
274318
{

0 commit comments

Comments
 (0)