[Issue#18] - Consistent parsing of all template variables

This commit is contained in:
abhijitkane
2019-05-15 01:21:53 +05:30
parent 23c8ca148b
commit a2bb828f17
2 changed files with 17 additions and 17 deletions

View File

@@ -89,23 +89,14 @@ module.exports = {
* @returns {string} string after replacing /{pet}/ with /:pet/
*/
fixPathVariablesInUrl: function (url) {
/*
The first .replace:
Handling path templating in request url if any
only replace /{pet}<end-of-string> or /{pet}/
https://regex101.com/r/Yqm2As/2
The second .replace:
we also need to replace the scheme variables
{scheme}://api.com
needs to become
{{scheme}}://api.com
and scheme is already set as a collection variable
*/
// All complicated logic removed
// This simply replaces all instances of {text} with {{text}}
// text cannot have any of these 3 chars: /{}
// and {text} cannot be followed by a }
// {{text}} will not be converted
// https://regex101.com/r/9N1520/1
return url
.replace(/\/\{([a-zA-Z0-9\-\_]+)\}(\/|$)/g, '/:$1$2')
.replace(/^\{([a-zA-Z0-9\-\_]+)\}\:/, '{{$1}}:');
.replace(/(\{[^\/\{\}]+\})(?!\})/g, '{$1}');
},
/**