From 0e4cafafec16b5f9ee85c37e64b961a76efbfa75 Mon Sep 17 00:00:00 2001 From: Andrii Iudin Date: Wed, 10 Jan 2018 16:53:14 +0000 Subject: [PATCH 1/3] Fix of an issue of having prototype Array function definitions. In this case the original code would go through all those functions and treat them as parameters, rather than working only on the actual content of an array. For example, having Array.prototype.last = function(){... defined would result in one of the elements of sharedParameters to represent that function, which in turn would lead to a problem on line 329 since for such a parameter, param.schema would be undefined --- .../static/rest_framework_swagger/swagger-ui.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/rest_framework_swagger/static/rest_framework_swagger/swagger-ui.js b/rest_framework_swagger/static/rest_framework_swagger/swagger-ui.js index b6e76790..ff104fab 100644 --- a/rest_framework_swagger/static/rest_framework_swagger/swagger-ui.js +++ b/rest_framework_swagger/static/rest_framework_swagger/swagger-ui.js @@ -2401,7 +2401,7 @@ Resolver.prototype.resolve = function (spec, arg1, arg2, arg3) { var sharedParameters = path.parameters || []; var parameters = operation.parameters || []; - for (i in sharedParameters) { + for (var i=0; i Date: Wed, 10 Jan 2018 16:55:53 +0000 Subject: [PATCH 2/3] Style consistency --- .../static/rest_framework_swagger/swagger-ui.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/rest_framework_swagger/static/rest_framework_swagger/swagger-ui.js b/rest_framework_swagger/static/rest_framework_swagger/swagger-ui.js index ff104fab..1c430e40 100644 --- a/rest_framework_swagger/static/rest_framework_swagger/swagger-ui.js +++ b/rest_framework_swagger/static/rest_framework_swagger/swagger-ui.js @@ -2401,7 +2401,7 @@ Resolver.prototype.resolve = function (spec, arg1, arg2, arg3) { var sharedParameters = path.parameters || []; var parameters = operation.parameters || []; - for (var i=0; i Date: Tue, 15 Jan 2019 12:58:06 +0000 Subject: [PATCH 3/3] Added a comment explaining the choice of the for loop to avoid possible rollbacks to the old code. --- .../rest_framework_swagger/swagger-ui.js | 328 +++++++++--------- 1 file changed, 165 insertions(+), 163 deletions(-) diff --git a/rest_framework_swagger/static/rest_framework_swagger/swagger-ui.js b/rest_framework_swagger/static/rest_framework_swagger/swagger-ui.js index 1c430e40..82c7e0d7 100644 --- a/rest_framework_swagger/static/rest_framework_swagger/swagger-ui.js +++ b/rest_framework_swagger/static/rest_framework_swagger/swagger-ui.js @@ -2401,6 +2401,8 @@ Resolver.prototype.resolve = function (spec, arg1, arg2, arg3) { var sharedParameters = path.parameters || []; var parameters = operation.parameters || []; + // "for i in object" loops through all the enumerable properties of the object itself and those the object + // inherits from its constructor's prototype, so it is safer to iterate through the length for (var i = 0; i < sharedParameters.length; i++) { var parameter = sharedParameters[i]; parameters.unshift(parameter); @@ -18988,169 +18990,169 @@ function request(RequestConstructor, method, url) { module.exports = request; },{}],162:[function(require,module,exports){ - -/** - * Expose `Emitter`. - */ - -if (typeof module !== 'undefined') { - module.exports = Emitter; -} - -/** - * Initialize a new `Emitter`. - * - * @api public - */ - -function Emitter(obj) { - if (obj) return mixin(obj); -}; - -/** - * Mixin the emitter properties. - * - * @param {Object} obj - * @return {Object} - * @api private - */ - -function mixin(obj) { - for (var key in Emitter.prototype) { - obj[key] = Emitter.prototype[key]; - } - return obj; -} - -/** - * Listen on the given `event` with `fn`. - * - * @param {String} event - * @param {Function} fn - * @return {Emitter} - * @api public - */ - -Emitter.prototype.on = -Emitter.prototype.addEventListener = function(event, fn){ - this._callbacks = this._callbacks || {}; - (this._callbacks['$' + event] = this._callbacks['$' + event] || []) - .push(fn); - return this; -}; - -/** - * Adds an `event` listener that will be invoked a single - * time then automatically removed. - * - * @param {String} event - * @param {Function} fn - * @return {Emitter} - * @api public - */ - -Emitter.prototype.once = function(event, fn){ - function on() { - this.off(event, on); - fn.apply(this, arguments); - } - - on.fn = fn; - this.on(event, on); - return this; -}; - -/** - * Remove the given callback for `event` or all - * registered callbacks. - * - * @param {String} event - * @param {Function} fn - * @return {Emitter} - * @api public - */ - -Emitter.prototype.off = -Emitter.prototype.removeListener = -Emitter.prototype.removeAllListeners = -Emitter.prototype.removeEventListener = function(event, fn){ - this._callbacks = this._callbacks || {}; - - // all - if (0 == arguments.length) { - this._callbacks = {}; - return this; - } - - // specific event - var callbacks = this._callbacks['$' + event]; - if (!callbacks) return this; - - // remove all handlers - if (1 == arguments.length) { - delete this._callbacks['$' + event]; - return this; - } - - // remove specific handler - var cb; - for (var i = 0; i < callbacks.length; i++) { - cb = callbacks[i]; - if (cb === fn || cb.fn === fn) { - callbacks.splice(i, 1); - break; - } - } - return this; -}; - -/** - * Emit `event` with the given args. - * - * @param {String} event - * @param {Mixed} ... - * @return {Emitter} - */ - -Emitter.prototype.emit = function(event){ - this._callbacks = this._callbacks || {}; - var args = [].slice.call(arguments, 1) - , callbacks = this._callbacks['$' + event]; - - if (callbacks) { - callbacks = callbacks.slice(0); - for (var i = 0, len = callbacks.length; i < len; ++i) { - callbacks[i].apply(this, args); - } - } - - return this; -}; - -/** - * Return array of callbacks for `event`. - * - * @param {String} event - * @return {Array} - * @api public - */ - -Emitter.prototype.listeners = function(event){ - this._callbacks = this._callbacks || {}; - return this._callbacks['$' + event] || []; -}; - -/** - * Check if this emitter has `event` handlers. - * - * @param {String} event - * @return {Boolean} - * @api public - */ - -Emitter.prototype.hasListeners = function(event){ - return !! this.listeners(event).length; -}; + +/** + * Expose `Emitter`. + */ + +if (typeof module !== 'undefined') { + module.exports = Emitter; +} + +/** + * Initialize a new `Emitter`. + * + * @api public + */ + +function Emitter(obj) { + if (obj) return mixin(obj); +}; + +/** + * Mixin the emitter properties. + * + * @param {Object} obj + * @return {Object} + * @api private + */ + +function mixin(obj) { + for (var key in Emitter.prototype) { + obj[key] = Emitter.prototype[key]; + } + return obj; +} + +/** + * Listen on the given `event` with `fn`. + * + * @param {String} event + * @param {Function} fn + * @return {Emitter} + * @api public + */ + +Emitter.prototype.on = +Emitter.prototype.addEventListener = function(event, fn){ + this._callbacks = this._callbacks || {}; + (this._callbacks['$' + event] = this._callbacks['$' + event] || []) + .push(fn); + return this; +}; + +/** + * Adds an `event` listener that will be invoked a single + * time then automatically removed. + * + * @param {String} event + * @param {Function} fn + * @return {Emitter} + * @api public + */ + +Emitter.prototype.once = function(event, fn){ + function on() { + this.off(event, on); + fn.apply(this, arguments); + } + + on.fn = fn; + this.on(event, on); + return this; +}; + +/** + * Remove the given callback for `event` or all + * registered callbacks. + * + * @param {String} event + * @param {Function} fn + * @return {Emitter} + * @api public + */ + +Emitter.prototype.off = +Emitter.prototype.removeListener = +Emitter.prototype.removeAllListeners = +Emitter.prototype.removeEventListener = function(event, fn){ + this._callbacks = this._callbacks || {}; + + // all + if (0 == arguments.length) { + this._callbacks = {}; + return this; + } + + // specific event + var callbacks = this._callbacks['$' + event]; + if (!callbacks) return this; + + // remove all handlers + if (1 == arguments.length) { + delete this._callbacks['$' + event]; + return this; + } + + // remove specific handler + var cb; + for (var i = 0; i < callbacks.length; i++) { + cb = callbacks[i]; + if (cb === fn || cb.fn === fn) { + callbacks.splice(i, 1); + break; + } + } + return this; +}; + +/** + * Emit `event` with the given args. + * + * @param {String} event + * @param {Mixed} ... + * @return {Emitter} + */ + +Emitter.prototype.emit = function(event){ + this._callbacks = this._callbacks || {}; + var args = [].slice.call(arguments, 1) + , callbacks = this._callbacks['$' + event]; + + if (callbacks) { + callbacks = callbacks.slice(0); + for (var i = 0, len = callbacks.length; i < len; ++i) { + callbacks[i].apply(this, args); + } + } + + return this; +}; + +/** + * Return array of callbacks for `event`. + * + * @param {String} event + * @return {Array} + * @api public + */ + +Emitter.prototype.listeners = function(event){ + this._callbacks = this._callbacks || {}; + return this._callbacks['$' + event] || []; +}; + +/** + * Check if this emitter has `event` handlers. + * + * @param {String} event + * @return {Boolean} + * @api public + */ + +Emitter.prototype.hasListeners = function(event){ + return !! this.listeners(event).length; +}; },{}],163:[function(require,module,exports){