Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

issue #19735: Fix critical flaw in setStatus. Git rid of bitwise comp…

…arison in set statement.
  • Loading branch information...
commit 4a2308ef9cad8899a69e4752cff1bd1a1e44f220 1 parent b910b44
John Rogelstad authored
Showing with 27 additions and 16 deletions.
  1. +27 −16 lib/backbone-x/source/model.js
View
43 lib/backbone-x/source/model.js
@@ -994,7 +994,7 @@ white:true*/
XT.log('No changes to save');
return false;
},
-
+
/**
Overload: Don't allow setting when model is in error or destroyed status, or
updating a `READY_CLEAN` record without update privileges.
@@ -1008,30 +1008,41 @@ white:true*/
keyIsObject = _.isObject(key),
status = this.getStatus(),
err;
-
+
// Handle both `"key", value` and `{key: value}` -style arguments.
if (keyIsObject) { options = val; }
options = options ? options : {};
-
- // Don't allow editing of records that are ineligable
- if (status === K.ERROR || (status & K.DESTROYED)) {
+
+ switch (status)
+ {
+ case K.ERROR:
+ case K.DESTROYED_CLEAN:
+ case K.DESTROYED_DIRTY:
+ // Set error if attempting to edit a record that is ineligable
err = XT.Error.clone('xt1009', { params: { status: status } });
- } else if (status === K.READY_CLEAN && !this.canUpdate()) {
- err = XT.Error.clone('xt1010');
- }
-
- // If we're not in a `READY` state, silence all events
- if (!this.isReady() && !_.isBoolean(options.silent)) {
- options.silent = true;
+ break;
+ case K.READY_CLEAN:
+ // Set error if no update privileges
+ if (!this.canUpdate()) { err = XT.Error.clone('xt1010'); }
+ break;
+ case K.READY_DIRTY:
+ case K.READY_NEW:
+ break;
+ default:
+ // If we're not in a `READY` state, silence all events
+ if (!_.isBoolean(options.silent)) {
+ options.silent = true;
+ }
}
-
+
+ // Raise error, if any
if (err) {
this.trigger('invalid', this, options);
return false;
}
-
- if (keyIsObject) { val = options; }
+ // Handle both `"key", value` and `{key: value}` -style arguments.
+ if (keyIsObject) { val = options; }
return Backbone.RelationalModel.prototype.set.call(this, key, val, options);
},
@@ -1143,7 +1154,7 @@ white:true*/
case K.DESTROYED_DIRTY:
dataState = 'delete';
}
- this.attributes.dataState = dataState;
+ if (dataState) { this.attributes.dataState = dataState; }
// Percolate changes up to parent when applicable
if (parent && (this.isDirty() ||
Please sign in to comment.
Something went wrong with that request. Please try again.