add more strict checks for twist .msg fields corectness

This commit is contained in:
Simon Grim 2016-03-25 04:50:28 +05:00
parent e5a8c44d11
commit 2a37be1a73
3 changed files with 11 additions and 5 deletions

View File

@ -157,8 +157,10 @@ function requestRTs(postLi)
}
function appendPostToElem(post, elem) {
// posts without 'msg' and 'rt.msg' may be used for metadata like 'url' and are not meant to be displayed
if (!post.userpost.msg && (!post.userpost.rt || (post.userpost.rt && !post.userpost.rt.msg)))
// posts without non-empty strings in both 'msg' and 'rt.msg' may be used for metadata like 'url' and are not meant to be displayed
if ((typeof post.userpost.msg !== 'string' || post.userpost.msg === '')
&& (typeof post.userpost.rt !== 'object'
|| typeof post.userpost.rt.msg !== 'string' || post.userpost.rt.msg === ''))
return;
postToElem(post, 'original').hide().appendTo(elem).slideDown('fast');

View File

@ -60,7 +60,7 @@ function postToElem(post, kind, promoted) {
if (post.sig_wort)
userpost.sig_wort = post.sig_wort;
if (userpost.rt && userpost.rt.msg) {
if (userpost.rt && typeof userpost.rt.msg === 'string' && userpost.rt.msg !== '') {
rt = userpost.rt;
if (userpost.msg) {
username = userpost.n;
@ -86,6 +86,8 @@ function postToElem(post, kind, promoted) {
content_to_rt = $.toJSON(userpost);
content_to_sigrt = post.sig_userpost;
}
if (typeof msg !== 'string')
msg = '';
// Now create the html elements
var elem = $.MAL.getPostTemplate().clone(true).appendTo(twister.html.detached);

View File

@ -347,8 +347,10 @@ function timelineChangedUser()
}
function willBeHidden(post) {
// posts without 'msg' and 'rt.msg' may be used for metadata like 'url' and are not meant to be displayed
if (!post.userpost.msg && (!post.userpost.rt || (post.userpost.rt && !post.userpost.rt.msg)))
// posts without non-empty strings in both 'msg' and 'rt.msg' may be used for metadata like 'url' and are not meant to be displayed
if ((typeof post.userpost.msg !== 'string' || post.userpost.msg === '')
&& (typeof post.userpost.rt !== 'object'
|| typeof post.userpost.rt.msg !== 'string' || post.userpost.rt.msg === ''))
return true;
if (post['userpost']['n'] === defaultScreenName)