Skip to content

Commit 5e1b16e

Browse files
author
Vishal Shingala
committed
Fixed an issue where for some invalid URLs, conversion was failing with type error
1 parent ab0436d commit 5e1b16e

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

lib/schemaUtils.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,11 @@ module.exports = {
314314
* @returns {string} string after replacing /{pet}/ with /:pet/
315315
*/
316316
fixPathVariablesInUrl: function (url) {
317+
// URL should always be string so update value if non-string value is found
318+
if (typeof url !== 'string') {
319+
return '';
320+
}
321+
317322
// All complicated logic removed
318323
// This simply replaces all instances of {text} with {{text}}
319324
// text cannot have any of these 3 chars: /{}

test/unit/util.test.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2567,6 +2567,18 @@ describe('SCHEMA UTILITY FUNCTION TESTS ', function () {
25672567

25682568
done();
25692569
});
2570+
2571+
it('should correctly handle non string values', function(done) {
2572+
expect(SchemaUtils.fixPathVariablesInUrl(123)).to.equal('');
2573+
2574+
expect(SchemaUtils.fixPathVariablesInUrl([])).to.equal('');
2575+
2576+
expect(SchemaUtils.fixPathVariablesInUrl({})).to.equal('');
2577+
2578+
expect(SchemaUtils.fixPathVariablesInUrl(true)).to.equal('');
2579+
2580+
done();
2581+
});
25702582
});
25712583

25722584
describe('findPathVariablesFromPath function', function() {

0 commit comments

Comments
 (0)