mirror of
https://github.com/meteor/meteor.git
synced 2026-05-02 03:01:46 -04:00
Fix prefix check. Remove all numeric keys from sel
This commit is contained in:
@@ -2433,5 +2433,17 @@ Tinytest.add("minimongo - modifier affects selector", function (test) {
|
||||
notAffected({ 'foo.bar': 0 }, { $set: { 'foo.baz': 1 } }, "simplest");
|
||||
affected({ 'foo.bar': 0 }, { $set: { 'foo.1': 1 } }, "simplest");
|
||||
affected({ 'foo.bar': 0 }, { $set: { 'foo.2.bar': 1 } }, "simplest");
|
||||
|
||||
notAffected({ 'foo': 0 }, { $set: { 'foobaz': 1 } }, "correct prefix check");
|
||||
notAffected({ 'foobar': 0 }, { $unset: { 'foo': 1 } }, "correct prefix check");
|
||||
notAffected({ 'foo.bar': 0 }, { $unset: { 'foob': 1 } }, "correct prefix check");
|
||||
|
||||
// XXX once we consider all the array/non-array operators separately, this
|
||||
// should become notAffected. Until then it's fine to let it "match" and
|
||||
// affect.
|
||||
//notAffected({ 'foo.3.bar': 0 }, { $set: { 'foo.2.bar': 1 } }, "observe for an array element");
|
||||
affected({ 'foo.3.bar': 0 }, { $set: { 'foo.2.bar': 1 } }, "observe for an array element");
|
||||
|
||||
affected({ 'foo.3.bar': 0 }, { $set: { 'foo.3.bar': 1 } }, "observe for an array element");
|
||||
});
|
||||
|
||||
|
||||
@@ -802,9 +802,9 @@ LocalCollection._isSelectorAffectedByModifier = function (selector, modifier) {
|
||||
return _.any(modifiedPaths, function (path) {
|
||||
path = removeNumericsKeys(path);
|
||||
return _.any(meaningfulPaths, function (meaningfulPath) {
|
||||
// It's full prefix
|
||||
return path.indexOf(meaningfulPath) === 0
|
||||
|| meaningfulPath.indexOf(path) === 0;
|
||||
meaningfulPath = removeNumericsKeys(meaningfulPath);
|
||||
return isPathPrefix(path, meaningfulPath)
|
||||
|| isPathPrefix(meaningfulPath, path);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -812,6 +812,11 @@ LocalCollection._isSelectorAffectedByModifier = function (selector, modifier) {
|
||||
return _.filter(path.split('.'), isNaN).join('.');
|
||||
}
|
||||
|
||||
function isPathPrefix (s, t) {
|
||||
var pos = t.indexOf(s);
|
||||
return pos === 0
|
||||
&& (pos + s.length === t.length || t[pos + s.length] === '.');
|
||||
}
|
||||
};
|
||||
|
||||
// Returns a list of key paths the given selector is looking for
|
||||
|
||||
Reference in New Issue
Block a user