Skip to content

Loading…

suite.js performs unsafe Object iterations without hasOwnProperty #175

Closed
wants to merge 3 commits into from

3 participants

@Sembiance

Even in node.js, it's possible that the Object prototype can be modified with additional properties.

When this happens it is causing vows to fail because vows isn't checking hasOwnProperty() to ensure it's a real property.

This pull request adds the two checks needed in suite.js

I've run npm test and tests pass.

This pull request is ready to be merged.

@Sembiance Sembiance Added hasOwnProperty() check to 'for(var key in obj)' loops so that e…
…xternal Object prototype manipulations can't cause vows to break
64b14a7
@Prinzhorn

I think your code still doesn't nail it 100%.

if (Object.prototype.hasOwnProperty.call(options, k))
@mmalecki mmalecki added a commit that closed this pull request
@mmalecki mmalecki [fix] Fix unsafe object iterations
Fixes #175.
4347cdd
@mmalecki mmalecki closed this in 4347cdd
@mmalecki

I went with 4347cdd, but thanks!

@Sembiance

@mmalecki that works too! Thanks for fixing this, I can now use the official vows module instead of my fork :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jan 3, 2012
  1. @Sembiance

    Added hasOwnProperty() check to 'for(var key in obj)' loops so that e…

    Sembiance committed
    …xternal Object prototype manipulations can't cause vows to break
Commits on Jan 19, 2012
  1. @Sembiance

    Changed hasOwnProperty check to use the prototype method just in case…

    Sembiance committed
    … it's been removed from the current object
Commits on Mar 2, 2012
  1. @Sembiance
Showing with 13 additions and 2 deletions.
  1. +13 −2 lib/vows/suite.js
View
15 lib/vows/suite.js
@@ -261,7 +261,12 @@ this.Suite.prototype = new(function () {
options = options || {};
- for (var k in options) { this.options[k] = options[k] }
+ for (var k in options) {
+ if (!Object.prototype.hasOwnProperty.call(options, k)) {
+ continue;
+ }
+ this.options[k] = options[k]
+ }
this.matcher = this.options.matcher || this.matcher;
this.reporter = this.options.reporter || this.reporter;
@@ -309,7 +314,13 @@ this.Suite.prototype = new(function () {
this.runParallel = function () {};
this.export = function (module, options) {
- for (var k in (options || {})) { this.options[k] = options[k] }
+ options = (options || {});
+ for (var k in options) {
+ if (!Object.prototype.hasOwnProperty.call(options, k)) {
+ continue;
+ }
+ this.options[k] = options[k]
+ }
if (require.main === module) {
return this.run();
Something went wrong with that request. Please try again.