JS: Add test and comment for access path termination criteria

This commit is contained in:
Asger Feldthaus
2021-07-16 09:42:54 +02:00
parent 0247de76af
commit be8c574d5c
2 changed files with 10 additions and 1 deletions

View File

@@ -53,7 +53,8 @@ module Vuex {
bindingset[base, prop]
private string appendToNamespace(string base, string prop) {
result = base + prop + "/" and
// Allow at most two occurrences of a given property name in the path
// To avoid constructing infinitely long access paths,
// allow at most two occurrences of a given property name in the path
// (one in the base, plus the one we're appending now).
count(base.indexOf("/" + prop + "/")) <= 1
}

View File

@@ -107,6 +107,14 @@ const Component = new Vue({
},
...mapMutations({ sneakyTaint3: 'setTainted3' }),
...mapActions({ emitTaint4: 'doTaint4' }),
loopingState() {
// Make sure we do not fail by trying to compute infinitely long access paths.
// 'ref' can refer to state.foo, state.foo.foo, state.foo.foo.foo, and so on.
let ref = this.$store.state;
while (Math.random()) {
ref = ref.foo;
}
}
}
});