1
0
mirror of https://github.com/matrix-org/matrix-js-sdk.git synced 2025-11-25 05:23:13 +03:00

Fix empty string handling in push notifications

Fixes https://github.com/vector-im/riot-web/issues/11460

Empty strings are falsey, and the state key match for a tombstone event is an empty string. Ergo, nothing happens because all the conditions fail.
This commit is contained in:
Travis Ralston
2019-11-25 16:35:27 -07:00
parent ccc85d98e2
commit aa37f697bf
2 changed files with 11 additions and 7 deletions

View File

@@ -15,7 +15,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
import {escapeRegExp, globToRegexp} from "./utils";
import {escapeRegExp, globToRegexp, isNullOrUndefined} from "./utils";
/**
* @module pushprocessor
@@ -268,7 +268,7 @@ function PushProcessor(client) {
}
const val = valueForDottedKey(cond.key, ev);
if (!val || typeof val != 'string') {
if (isNullOrUndefined(val) || typeof val != 'string') {
return false;
}
@@ -304,10 +304,10 @@ function PushProcessor(client) {
// special-case the first component to deal with encrypted messages
const firstPart = parts[0];
if (firstPart == 'content') {
if (firstPart === 'content') {
val = ev.getContent();
parts.shift();
} else if (firstPart == 'type') {
} else if (firstPart === 'type') {
val = ev.getType();
parts.shift();
} else {
@@ -316,11 +316,11 @@ function PushProcessor(client) {
}
while (parts.length > 0) {
const thispart = parts.shift();
if (!val[thispart]) {
const thisPart = parts.shift();
if (isNullOrUndefined(val[thisPart])) {
return null;
}
val = val[thispart];
val = val[thisPart];
}
return val;
};

View File

@@ -714,3 +714,7 @@ module.exports.ensureNoTrailingSlash = function(url) {
module.exports.sleep = (ms, value) => new Promise((resolve => {
setTimeout(resolve, ms, value);
}));
module.exports.isNullOrUndefined = function(val) {
return val === null || val === undefined;
};