Skip to content

Commit e1a9d51

Browse files
authored
Merge pull request #640 from postmanlabs/feature/fix-non-string-urls
Fixed issue where for non-string URLs, conversion process was failing with TypeError.
2 parents 566cf3b + 2c31495 commit e1a9d51

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
@@ -367,6 +367,11 @@ module.exports = {
367367
* @returns {string} string after replacing /{pet}/ with /:pet/
368368
*/
369369
fixPathVariablesInUrl: function (url) {
370+
// URL should always be string so update value if non-string value is found
371+
if (typeof url !== 'string') {
372+
return '';
373+
}
374+
370375
// All complicated logic removed
371376
// This simply replaces all instances of {text} with {{text}}
372377
// 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
@@ -2654,6 +2654,18 @@ describe('SCHEMA UTILITY FUNCTION TESTS ', function () {
26542654

26552655
done();
26562656
});
2657+
2658+
it('should correctly handle non string values', function(done) {
2659+
expect(SchemaUtils.fixPathVariablesInUrl(123)).to.equal('');
2660+
2661+
expect(SchemaUtils.fixPathVariablesInUrl([])).to.equal('');
2662+
2663+
expect(SchemaUtils.fixPathVariablesInUrl({})).to.equal('');
2664+
2665+
expect(SchemaUtils.fixPathVariablesInUrl(true)).to.equal('');
2666+
2667+
done();
2668+
});
26572669
});
26582670

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

0 commit comments

Comments
 (0)