jenkins-bot has submitted this change and it was merged.
Change subject: Fix for custom hash with keys in different order
......................................................................
Fix for custom hash with keys in different order
Instead of returning val when a custom hash is found,
feed it back into val and let the object sorting take
place if required.
Bug: 46895
Change-Id: I6a9b42facd97fbf49042d3a082121ec93659b9f1
---
M modules/ve/test/ve.test.js
M modules/ve/ve.js
2 files changed, 55 insertions(+), 20 deletions(-)
Approvals:
Krinkle: Looks good to me, approved
Catrope: Looks good to me, approved
jenkins-bot: Verified
diff --git a/modules/ve/test/ve.test.js b/modules/ve/test/ve.test.js
index 80d15a8..b93bfcb 100644
--- a/modules/ve/test/ve.test.js
+++ b/modules/ve/test/ve.test.js
@@ -132,42 +132,77 @@
// ve.extendObject: Tested upstream (jQuery)
-QUnit.test( 'getHash: Basic usage', 5, function ( assert ) {
- var tmp, hash, objects;
+QUnit.test( 'getHash: Basic usage', 7, function ( assert ) {
+ var tmp,
+ cases = {},
+ hash = '{"a":1,"b":1,"c":1}',
+ customHash = '{"first":1,"last":1}';
- objects = {};
-
- objects['a-z literal'] = {
- a: 1,
- b: 1,
- c: 1
+ cases['a-z literal'] = {
+ object: {
+ a: 1,
+ b: 1,
+ c: 1
+ },
+ hash: hash
};
- objects['z-a literal'] = {
- c: 1,
- b: 1,
- a: 1
+ cases['z-a literal'] = {
+ object: {
+ c: 1,
+ b: 1,
+ a: 1
+ },
+ hash: hash
};
tmp = {};
- objects['a-z augmented'] = tmp;
+ cases['a-z augmented'] = {
+ object: tmp,
+ hash: hash
+ };
tmp.a = 1;
tmp.b = 1;
tmp.c = 1;
tmp = {};
- objects['z-a augmented'] = tmp;
+ cases['z-a augmented'] = {
+ object: tmp,
+ hash: hash
+ };
tmp.c = 1;
tmp.b = 1;
tmp.a = 1;
- hash = '{"a":1,"b":1,"c":1}';
+ cases['custom hash'] = {
+ object: {
+ getHashObject: function () {
+ return {
+ 'first': 1,
+ 'last': 1
+ };
+ }
+ },
+ hash: customHash
+ };
- $.each( objects, function ( key, val ) {
+ cases['custom hash reversed'] = {
+ object: {
+ getHashObject: function () {
+ return {
+ 'last': 1,
+ 'first': 1
+ };
+ }
+ },
+ hash: customHash
+ };
+
+ $.each( cases, function ( key, val ) {
assert.equal(
- ve.getHash( val ),
- hash,
- 'Similar enough objects have the same hash, regardless
of "property order"'
+ ve.getHash( val.object ),
+ val.hash,
+ key + ': object has expected hash, regardless of
"property order"'
);
});
diff --git a/modules/ve/ve.js b/modules/ve/ve.js
index 651b374..720e224 100644
--- a/modules/ve/ve.js
+++ b/modules/ve/ve.js
@@ -319,7 +319,7 @@
var normalized, keys, i, len;
if ( val && typeof val.getHashObject === 'function' ) {
// This object has its own custom hash function, use it
- return val.getHashObject();
+ val = val.getHashObject();
}
if ( !ve.isArray( val ) && Object( val ) === val ) {
// Only normalize objects when the key-order is
ambiguous
--
To view, visit https://gerrit.wikimedia.org/r/58241
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I6a9b42facd97fbf49042d3a082121ec93659b9f1
Gerrit-PatchSet: 2
Gerrit-Project: mediawiki/extensions/VisualEditor
Gerrit-Branch: master
Gerrit-Owner: Esanders <[email protected]>
Gerrit-Reviewer: Catrope <[email protected]>
Gerrit-Reviewer: Jforrester <[email protected]>
Gerrit-Reviewer: Krinkle <[email protected]>
Gerrit-Reviewer: jenkins-bot
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits