From b8aa529adce7117fb391cfe3526165d7bdb20a54 Mon Sep 17 00:00:00 2001
From: Bob Mottram
Date: Wed, 23 Mar 2022 22:43:19 +0000
Subject: [PATCH 01/24] Only show follows status if authorized
---
webapp_person_options.py | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/webapp_person_options.py b/webapp_person_options.py
index 90867b033..9c2797b55 100644
--- a/webapp_person_options.py
+++ b/webapp_person_options.py
@@ -151,7 +151,7 @@ def html_person_options(default_timeline: str,
options_str += \
' ' + translate['Options for'] + \
' @' + handle_shown + '
\n'
- if follows_you:
+ if follows_you and authorized:
options_str += \
' ' + translate['Follows you'] + '
\n'
if moved_to:
From aab90e75da469a326a6547a96bfba92055bca86b Mon Sep 17 00:00:00 2001
From: Bob Mottram
Date: Wed, 23 Mar 2022 22:49:37 +0000
Subject: [PATCH 02/24] Check for no domain
---
daemon.py | 15 +++++++++------
webapp_person_options.py | 2 ++
2 files changed, 11 insertions(+), 6 deletions(-)
diff --git a/daemon.py b/daemon.py
index 1c3d22acb..6c09e26cc 100644
--- a/daemon.py
+++ b/daemon.py
@@ -7765,12 +7765,15 @@ class PubServer(BaseHTTPRequestHandler):
self.server.news_instance,
authorized,
access_keys, is_group).encode('utf-8')
- msglen = len(msg)
- self._set_headers('text/html', msglen,
- cookie, calling_domain, False)
- self._write(msg)
- fitness_performance(getreq_start_time, self.server.fitness,
- '_GET', '_show_person_options', debug)
+ if msg:
+ msglen = len(msg)
+ self._set_headers('text/html', msglen,
+ cookie, calling_domain, False)
+ self._write(msg)
+ fitness_performance(getreq_start_time, self.server.fitness,
+ '_GET', '_show_person_options', debug)
+ else:
+ self._404()
return
if '/users/news/' in path:
diff --git a/webapp_person_options.py b/webapp_person_options.py
index 9c2797b55..4a78d3a5d 100644
--- a/webapp_person_options.py
+++ b/webapp_person_options.py
@@ -66,6 +66,8 @@ def html_person_options(default_timeline: str,
"""Show options for a person: view/follow/block/report
"""
options_domain, options_port = get_domain_from_actor(options_actor)
+ if not options_domain:
+ return None
options_domain_full = get_full_domain(options_domain, options_port)
if os.path.isfile(base_dir + '/accounts/options-background-custom.jpg'):
From f55f7a258f784d5b9e5c4b283f0d4c7c1bf15ebb Mon Sep 17 00:00:00 2001
From: Bob Mottram
Date: Wed, 23 Mar 2022 23:59:29 +0000
Subject: [PATCH 03/24] Handle none return valued from nickname
---
announce.py | 15 +--
availability.py | 2 +
bookmarks.py | 4 +
daemon.py | 215 +++++++++++++++++++++++++++++----------
inbox.py | 18 +++-
posts.py | 3 +
reaction.py | 2 +
skills.py | 2 +
utils.py | 6 ++
webapp_calendar.py | 4 +
webapp_confirm.py | 30 ++++--
webapp_hashtagswarm.py | 2 +
webapp_likers.py | 2 +
webapp_moderation.py | 10 ++
webapp_person_options.py | 7 +-
webapp_post.py | 17 +++-
webapp_profile.py | 2 +
webapp_search.py | 2 +
webapp_utils.py | 4 +
19 files changed, 266 insertions(+), 81 deletions(-)
diff --git a/announce.py b/announce.py
index f4c041f93..228295042 100644
--- a/announce.py
+++ b/announce.py
@@ -187,13 +187,14 @@ def create_announce(session, base_dir: str, federation_list: [],
group_account = False
if has_users_path(object_url):
announce_nickname = get_nickname_from_actor(object_url)
- announce_domain, announce_port = get_domain_from_actor(object_url)
- if '/' + str(announce_nickname) + '/' in object_url:
- announce_actor = \
- object_url.split('/' + announce_nickname + '/')[0] + \
- '/' + announce_nickname
- if has_group_type(base_dir, announce_actor, person_cache):
- group_account = True
+ if announce_nickname:
+ announce_domain, announce_port = get_domain_from_actor(object_url)
+ if '/' + str(announce_nickname) + '/' in object_url:
+ announce_actor = \
+ object_url.split('/' + announce_nickname + '/')[0] + \
+ '/' + announce_nickname
+ if has_group_type(base_dir, announce_actor, person_cache):
+ group_account = True
if announce_nickname and announce_domain:
send_signed_json(new_announce, session, base_dir,
diff --git a/availability.py b/availability.py
index 4c2528505..fdb913749 100644
--- a/availability.py
+++ b/availability.py
@@ -68,6 +68,8 @@ def outbox_availability(base_dir: str, nickname: str, message_json: {},
return False
actor_nickname = get_nickname_from_actor(message_json['actor'])
+ if not actor_nickname:
+ return False
if actor_nickname != nickname:
return False
domain, _ = get_domain_from_actor(message_json['actor'])
diff --git a/bookmarks.py b/bookmarks.py
index b2399c8d2..5ee5478d9 100644
--- a/bookmarks.py
+++ b/bookmarks.py
@@ -46,6 +46,8 @@ def undo_bookmarks_collection_entry(recent_posts_cache: {},
# remove any cached version of this post so that the
# bookmark icon is changed
nickname = get_nickname_from_actor(actor)
+ if not nickname:
+ return
cached_post_filename = \
get_cached_post_filename(base_dir, nickname,
domain, post_json_object)
@@ -166,6 +168,8 @@ def update_bookmarks_collection(recent_posts_cache: {},
# remove any cached version of this post so that the
# bookmark icon is changed
nickname = get_nickname_from_actor(actor)
+ if not nickname:
+ return
cached_post_filename = \
get_cached_post_filename(base_dir, nickname,
domain, post_json_object)
diff --git a/daemon.py b/daemon.py
index 6c09e26cc..68a00c0dc 100644
--- a/daemon.py
+++ b/daemon.py
@@ -2195,18 +2195,24 @@ class PubServer(BaseHTTPRequestHandler):
if '/@' in search_handle:
search_nickname = \
get_nickname_from_actor(search_handle)
- search_domain, _ = \
- get_domain_from_actor(search_handle)
- search_handle = \
- search_nickname + '@' + search_domain
- if '@' not in search_handle:
- if search_handle.startswith('http'):
- search_nickname = \
- get_nickname_from_actor(search_handle)
+ if search_nickname:
search_domain, _ = \
get_domain_from_actor(search_handle)
search_handle = \
search_nickname + '@' + search_domain
+ else:
+ search_handle = None
+ if '@' not in search_handle:
+ if search_handle.startswith('http'):
+ search_nickname = \
+ get_nickname_from_actor(search_handle)
+ if search_nickname:
+ search_domain, _ = \
+ get_domain_from_actor(search_handle)
+ search_handle = \
+ search_nickname + '@' + search_domain
+ else:
+ search_handle = None
if '@' not in search_handle:
# is this a local nickname on this instance?
local_handle = \
@@ -2234,11 +2240,12 @@ class PubServer(BaseHTTPRequestHandler):
self.server.translate,
base_dir, http_prefix,
nickname)
- msg = msg.encode('utf-8')
- msglen = len(msg)
- self._login_headers('text/html',
- msglen, calling_domain)
- self._write(msg)
+ if msg:
+ msg = msg.encode('utf-8')
+ msglen = len(msg)
+ self._login_headers('text/html',
+ msglen, calling_domain)
+ self._write(msg)
self.server.postreq_busy = False
return
elif moderation_str.startswith('submitBlock'):
@@ -3088,11 +3095,13 @@ class PubServer(BaseHTTPRequestHandler):
options_actor,
self.server.debug,
self.server.system_language,
- signing_priv_key_pem).encode('utf-8')
- msglen = len(msg)
- self._set_headers('text/html', msglen,
- cookie, calling_domain, False)
- self._write(msg)
+ signing_priv_key_pem)
+ if msg:
+ msg = msg.encode('utf-8')
+ msglen = len(msg)
+ self._set_headers('text/html', msglen,
+ cookie, calling_domain, False)
+ self._write(msg)
self.server.postreq_busy = False
return
else:
@@ -3227,6 +3236,11 @@ class PubServer(BaseHTTPRequestHandler):
users_path = path.split('/unfollowconfirm')[0]
origin_path_str = http_prefix + '://' + domain_full + users_path
follower_nickname = get_nickname_from_actor(origin_path_str)
+ if not follower_nickname:
+ self.send_response(400)
+ self.end_headers()
+ self.server.postreq_busy = False
+ return
length = int(self.headers['Content-length'])
@@ -3257,6 +3271,11 @@ class PubServer(BaseHTTPRequestHandler):
if '&' in following_actor:
following_actor = following_actor.split('&')[0]
following_nickname = get_nickname_from_actor(following_actor)
+ if not following_nickname:
+ self.send_response(400)
+ self.end_headers()
+ self.server.postreq_busy = False
+ return
following_domain, following_port = \
get_domain_from_actor(following_actor)
following_domain_full = \
@@ -3318,6 +3337,11 @@ class PubServer(BaseHTTPRequestHandler):
users_path = path.split('/followconfirm')[0]
origin_path_str = http_prefix + '://' + domain_full + users_path
follower_nickname = get_nickname_from_actor(origin_path_str)
+ if not follower_nickname:
+ self.send_response(400)
+ self.end_headers()
+ self.server.postreq_busy = False
+ return
length = int(self.headers['Content-length'])
@@ -3358,6 +3382,11 @@ class PubServer(BaseHTTPRequestHandler):
if '&' in following_actor:
following_actor = following_actor.split('&')[0]
following_nickname = get_nickname_from_actor(following_actor)
+ if not following_nickname:
+ self.send_response(400)
+ self.end_headers()
+ self.server.postreq_busy = False
+ return
following_domain, following_port = \
get_domain_from_actor(following_actor)
if follower_nickname == following_nickname and \
@@ -3664,6 +3693,12 @@ class PubServer(BaseHTTPRequestHandler):
search_str = ':' + search_str + ':'
if search_str.startswith('#'):
nickname = get_nickname_from_actor(actor_str)
+ if not nickname:
+ self.send_response(400)
+ self.end_headers()
+ self.server.postreq_busy = False
+ return
+
# hashtag search
timezone = None
if self.server.account_timezone.get(nickname):
@@ -3761,6 +3796,11 @@ class PubServer(BaseHTTPRequestHandler):
break
# your post history search
nickname = get_nickname_from_actor(actor_str)
+ if not nickname:
+ self.send_response(400)
+ self.end_headers()
+ self.server.postreq_busy = False
+ return
search_str = search_str.replace("'", '', 1).strip()
timezone = None
if self.server.account_timezone.get(nickname):
@@ -3834,6 +3874,11 @@ class PubServer(BaseHTTPRequestHandler):
break
# bookmark search
nickname = get_nickname_from_actor(actor_str)
+ if not nickname:
+ self.send_response(400)
+ self.end_headers()
+ self.server.postreq_busy = False
+ return
search_str = search_str.replace('-', '', 1).strip()
timezone = None
if self.server.account_timezone.get(nickname):
@@ -3890,6 +3935,11 @@ class PubServer(BaseHTTPRequestHandler):
return
# profile search
nickname = get_nickname_from_actor(actor_str)
+ if not nickname:
+ self.send_response(400)
+ self.end_headers()
+ self.server.postreq_busy = False
+ return
profile_path_str = path.replace('/searchhandle', '')
# are we already following the searched for handle?
@@ -3897,6 +3947,11 @@ class PubServer(BaseHTTPRequestHandler):
# get the actor
if not has_users_path(search_str):
search_nickname = get_nickname_from_actor(search_str)
+ if not search_nickname:
+ self.send_response(400)
+ self.end_headers()
+ self.server.postreq_busy = False
+ return
search_domain, search_port = \
get_domain_from_actor(search_str)
search_domain_full = \
@@ -4310,6 +4365,11 @@ class PubServer(BaseHTTPRequestHandler):
local_actor_url(http_prefix, admin_nickname, domain_full)
actor = origin_path_str
actor_nickname = get_nickname_from_actor(actor)
+ if not actor_nickname:
+ self.send_response(400)
+ self.end_headers()
+ self.server.postreq_busy = False
+ return
if actor == share_actor or actor == admin_actor or \
is_moderator(base_dir, actor_nickname):
item_id = remove_share_confirm_params.split('itemID=')[1]
@@ -4378,6 +4438,11 @@ class PubServer(BaseHTTPRequestHandler):
local_actor_url(http_prefix, admin_nickname, domain_full)
actor = origin_path_str
actor_nickname = get_nickname_from_actor(actor)
+ if not actor_nickname:
+ self.send_response(400)
+ self.end_headers()
+ self.server.postreq_busy = False
+ return
if actor == share_actor or actor == admin_actor or \
is_moderator(base_dir, actor_nickname):
item_id = remove_share_confirm_params.split('itemID=')[1]
@@ -4921,6 +4986,9 @@ class PubServer(BaseHTTPRequestHandler):
users_path = path.replace('/citationsdata', '')
actor_str = self._get_instance_url(calling_domain) + users_path
nickname = get_nickname_from_actor(actor_str)
+ if not nickname:
+ self.server.postreq_busy = False
+ return
citations_filename = \
acct_dir(base_dir, nickname, domain) + '/.citations.txt'
@@ -7764,8 +7832,9 @@ class PubServer(BaseHTTPRequestHandler):
self.server.text_mode_banner,
self.server.news_instance,
authorized,
- access_keys, is_group).encode('utf-8')
+ access_keys, is_group)
if msg:
+ msg = msg.encode('utf-8')
msglen = len(msg)
self._set_headers('text/html', msglen,
cookie, calling_domain, False)
@@ -8547,6 +8616,9 @@ class PubServer(BaseHTTPRequestHandler):
following_handle = path.split('/followapprove=')[1]
if '://' in following_handle:
handle_nickname = get_nickname_from_actor(following_handle)
+ if not handle_nickname:
+ self._404()
+ return
handle_domain, handle_port = \
get_domain_from_actor(following_handle)
following_handle = \
@@ -8733,6 +8805,9 @@ class PubServer(BaseHTTPRequestHandler):
following_handle = path.split('/followdeny=')[1]
if '://' in following_handle:
handle_nickname = get_nickname_from_actor(following_handle)
+ if not handle_nickname:
+ self._404()
+ return
handle_domain, handle_port = \
get_domain_from_actor(following_handle)
following_handle = \
@@ -10105,6 +10180,9 @@ class PubServer(BaseHTTPRequestHandler):
actor = \
http_prefix + '://' + domain_full + path.split('?mute=')[0]
nickname = get_nickname_from_actor(actor)
+ if not nickname:
+ self._404()
+ return
mute_post(base_dir, nickname, domain, port,
http_prefix, mute_url,
self.server.recent_posts_cache, debug)
@@ -10226,6 +10304,9 @@ class PubServer(BaseHTTPRequestHandler):
actor = \
http_prefix + '://' + domain_full + path.split('?unmute=')[0]
nickname = get_nickname_from_actor(actor)
+ if not nickname:
+ self._404()
+ return
unmute_post(base_dir, nickname, domain, port,
http_prefix, mute_url,
self.server.recent_posts_cache, debug)
@@ -13817,6 +13898,9 @@ class PubServer(BaseHTTPRequestHandler):
"""Shows a QR code for an account
"""
nickname = get_nickname_from_actor(path)
+ if not nickname:
+ self._404()
+ return True
if onion_domain:
qrcode_domain = onion_domain
port = 80
@@ -13866,6 +13950,9 @@ class PubServer(BaseHTTPRequestHandler):
"""Shows a banner image on the search screen
"""
nickname = get_nickname_from_actor(path)
+ if not nickname:
+ self._404()
+ return True
banner_filename = \
acct_dir(base_dir, nickname, domain) + '/search_banner.png'
if not os.path.isfile(banner_filename):
@@ -14256,7 +14343,9 @@ class PubServer(BaseHTTPRequestHandler):
break
if is_new_post_endpoint:
nickname = get_nickname_from_actor(path)
-
+ if not nickname:
+ self._404()
+ return True
if in_reply_to_url:
reply_interval_hours = self.server.default_reply_interval_hrs
if not can_reply_to(base_dir, nickname, domain,
@@ -14403,8 +14492,9 @@ class PubServer(BaseHTTPRequestHandler):
access_keys,
default_reply_interval_hrs,
self.server.cw_lists,
- self.server.lists_enabled).encode('utf-8')
+ self.server.lists_enabled)
if msg:
+ msg = msg.encode('utf-8')
msglen = len(msg)
self._set_headers('text/html', msglen,
cookie, calling_domain, False)
@@ -14436,8 +14526,9 @@ class PubServer(BaseHTTPRequestHandler):
port,
http_prefix,
self.server.default_timeline,
- theme, access_keys).encode('utf-8')
+ theme, access_keys)
if msg:
+ msg = msg.encode('utf-8')
msglen = len(msg)
self._set_headers('text/html', msglen,
cookie, calling_domain, False)
@@ -14470,8 +14561,9 @@ class PubServer(BaseHTTPRequestHandler):
http_prefix,
self.server.default_timeline,
self.server.theme_name,
- access_keys).encode('utf-8')
+ access_keys)
if msg:
+ msg = msg.encode('utf-8')
msglen = len(msg)
self._set_headers('text/html', msglen,
cookie, calling_domain, False)
@@ -15810,6 +15902,9 @@ class PubServer(BaseHTTPRequestHandler):
if html_getreq and authorized and users_in_path and \
self.path.endswith('/followingaccounts'):
nickname = get_nickname_from_actor(self.path)
+ if not nickname:
+ self._404()
+ return
following_filename = \
acct_dir(self.server.base_dir,
nickname, self.server.domain) + '/following.txt'
@@ -16574,14 +16669,16 @@ class PubServer(BaseHTTPRequestHandler):
self.server.default_timeline,
self.server.theme_name,
self.server.text_mode_banner,
- access_keys).encode('utf-8')
- msglen = len(msg)
- self._set_headers('text/html', msglen, cookie, calling_domain,
- False)
- self._write(msg)
- fitness_performance(getreq_start_time, self.server.fitness,
- '_GET', 'search screen shown',
- self.server.debug)
+ access_keys)
+ if msg:
+ msg = msg.encode('utf-8')
+ msglen = len(msg)
+ self._set_headers('text/html', msglen, cookie,
+ calling_domain, False)
+ self._write(msg)
+ fitness_performance(getreq_start_time, self.server.fitness,
+ '_GET', 'search screen shown',
+ self.server.debug)
self.server.getreq_busy = False
return
@@ -16628,20 +16725,24 @@ class PubServer(BaseHTTPRequestHandler):
self.server.domain_full,
self.server.text_mode_banner,
access_keys,
- False).encode('utf-8')
- msglen = len(msg)
- if 'ical=true' in self.path:
- self._set_headers('text/calendar',
- msglen, cookie, calling_domain,
- False)
+ False)
+ if msg:
+ msg = msg.encode('utf-8')
+ msglen = len(msg)
+ if 'ical=true' in self.path:
+ self._set_headers('text/calendar',
+ msglen, cookie, calling_domain,
+ False)
+ else:
+ self._set_headers('text/html',
+ msglen, cookie, calling_domain,
+ False)
+ self._write(msg)
+ fitness_performance(getreq_start_time, self.server.fitness,
+ '_GET', 'calendar shown',
+ self.server.debug)
else:
- self._set_headers('text/html',
- msglen, cookie, calling_domain,
- False)
- self._write(msg)
- fitness_performance(getreq_start_time, self.server.fitness,
- '_GET', 'calendar shown',
- self.server.debug)
+ self._404()
self.server.getreq_busy = False
return
@@ -17213,6 +17314,10 @@ class PubServer(BaseHTTPRequestHandler):
if ';' in actor:
actor = actor.split(';')[0]
nickname = get_nickname_from_actor(self.path.split('?')[0])
+ if not nickname:
+ self._404()
+ self.server.getreq_busy = False
+ return
if nickname == actor:
post_url = \
local_actor_url(self.server.http_prefix, nickname,
@@ -17715,11 +17820,12 @@ class PubServer(BaseHTTPRequestHandler):
self.server.debug,
self.server.system_language,
self.server.signing_priv_key_pem)
- msg = msg.encode('utf-8')
- msglen = len(msg)
- self._login_headers('text/html',
- msglen, calling_domain)
- self._write(msg)
+ if msg:
+ msg = msg.encode('utf-8')
+ msglen = len(msg)
+ self._login_headers('text/html',
+ msglen, calling_domain)
+ self._write(msg)
self.server.getreq_busy = False
return
@@ -17752,11 +17858,12 @@ class PubServer(BaseHTTPRequestHandler):
self.server.debug,
self.server.system_language,
self.server.signing_priv_key_pem)
- msg = msg.encode('utf-8')
- msglen = len(msg)
- self._login_headers('text/html',
- msglen, calling_domain)
- self._write(msg)
+ if msg:
+ msg = msg.encode('utf-8')
+ msglen = len(msg)
+ self._login_headers('text/html',
+ msglen, calling_domain)
+ self._write(msg)
self.server.getreq_busy = False
return
diff --git a/inbox.py b/inbox.py
index 2aeb4df21..b02514e0e 100644
--- a/inbox.py
+++ b/inbox.py
@@ -1941,6 +1941,9 @@ def _receive_announce(recent_posts_cache: {},
# is the announce actor blocked?
nickname = handle.split('@')[0]
actor_nickname = get_nickname_from_actor(message_json['actor'])
+ if not actor_nickname:
+ print('WARN: _receive_announce no actor_nickname')
+ return False
actor_domain, _ = get_domain_from_actor(message_json['actor'])
if is_blocked(base_dir, nickname, domain, actor_nickname, actor_domain):
print('Receive announce blocked for actor: ' +
@@ -1948,13 +1951,16 @@ def _receive_announce(recent_posts_cache: {},
return False
# also check the actor for the url being announced
- announcedActorNickname = get_nickname_from_actor(message_json['object'])
+ announced_actor_nickname = get_nickname_from_actor(message_json['object'])
+ if not announced_actor_nickname:
+ print('WARN: _receive_announce no announced_actor_nickname')
+ return False
announcedActorDomain, announcedActorPort = \
get_domain_from_actor(message_json['object'])
if is_blocked(base_dir, nickname, domain,
- announcedActorNickname, announcedActorDomain):
+ announced_actor_nickname, announcedActorDomain):
print('Receive announce object blocked for actor: ' +
- announcedActorNickname + '@' + announcedActorDomain)
+ announced_actor_nickname + '@' + announcedActorDomain)
return False
# is this post in the outbox of the person?
@@ -2788,6 +2794,8 @@ def _inbox_update_calendar(base_dir: str, handle: str,
actor = post_json_object['actor']
actor_nickname = get_nickname_from_actor(actor)
+ if not actor_nickname:
+ return
actor_domain, _ = get_domain_from_actor(actor)
handle_nickname = handle.split('@')[0]
handle_domain = handle.split('@')[1]
@@ -3254,6 +3262,8 @@ def _low_frequency_post_notification(base_dir: str, http_prefix: str,
if not isinstance(attributed_to, str):
return
from_nickname = get_nickname_from_actor(attributed_to)
+ if not from_nickname:
+ return
from_domain, from_port = get_domain_from_actor(attributed_to)
from_domain_full = get_full_domain(from_domain, from_port)
if notify_when_person_posts(base_dir, nickname, domain,
@@ -3282,6 +3292,8 @@ def _check_for_git_patches(base_dir: str, nickname: str, domain: str,
if not isinstance(attributed_to, str):
return 0
from_nickname = get_nickname_from_actor(attributed_to)
+ if not from_nickname:
+ return 0
from_domain, from_port = get_domain_from_actor(attributed_to)
from_domain_full = get_full_domain(from_domain, from_port)
if receive_git_patch(base_dir, nickname, domain,
diff --git a/posts.py b/posts.py
index 9d43ae88a..18445b70a 100644
--- a/posts.py
+++ b/posts.py
@@ -4815,6 +4815,9 @@ def download_announce(session, base_dir: str, http_prefix: str,
'Accept': accept_str
}
actor_nickname = get_nickname_from_actor(post_json_object['actor'])
+ if not actor_nickname:
+ print('WARN: download_announce no actor_nickname')
+ return None
actor_domain, actor_port = \
get_domain_from_actor(post_json_object['actor'])
if not actor_domain:
diff --git a/reaction.py b/reaction.py
index e2804c61f..7dc2439b1 100644
--- a/reaction.py
+++ b/reaction.py
@@ -541,6 +541,8 @@ def html_emoji_reactions(post_json_object: {}, interactive: bool,
emoji_content = item['content']
emoji_actor = item['actor']
emoji_nickname = get_nickname_from_actor(emoji_actor)
+ if not emoji_nickname:
+ return ''
emoji_domain, _ = get_domain_from_actor(emoji_actor)
emoji_handle = emoji_nickname + '@' + emoji_domain
if emoji_actor == actor:
diff --git a/skills.py b/skills.py
index b1ac666b1..f7ce6e14e 100644
--- a/skills.py
+++ b/skills.py
@@ -158,6 +158,8 @@ def outbox_skills(base_dir: str, nickname: str, message_json: {},
return False
actor_nickname = get_nickname_from_actor(message_json['actor'])
+ if not actor_nickname:
+ return False
if actor_nickname != nickname:
return False
domain, _ = get_domain_from_actor(message_json['actor'])
diff --git a/utils.py b/utils.py
index 5158ae9b1..1cd72cbe7 100644
--- a/utils.py
+++ b/utils.py
@@ -2343,6 +2343,8 @@ def undo_likes_collection_entry(recent_posts_cache: {},
# remove any cached version of this post so that the
# like icon is changed
nickname = get_nickname_from_actor(actor)
+ if not nickname:
+ return
cached_post_filename = \
get_cached_post_filename(base_dir, nickname,
domain, post_json_object)
@@ -2409,6 +2411,8 @@ def undo_reaction_collection_entry(recent_posts_cache: {},
# remove any cached version of this post so that the
# like icon is changed
nickname = get_nickname_from_actor(actor)
+ if not nickname:
+ return
cached_post_filename = \
get_cached_post_filename(base_dir, nickname,
domain, post_json_object)
@@ -2476,6 +2480,8 @@ def undo_announce_collection_entry(recent_posts_cache: {},
# remove any cached version of this announce so that the announce
# icon is changed
nickname = get_nickname_from_actor(actor)
+ if not nickname:
+ return
cached_post_filename = \
get_cached_post_filename(base_dir, nickname, domain,
post_json_object)
diff --git a/webapp_calendar.py b/webapp_calendar.py
index 576fae8e3..d0901bad9 100644
--- a/webapp_calendar.py
+++ b/webapp_calendar.py
@@ -42,6 +42,8 @@ def html_calendar_delete_confirm(css_cache: {}, translate: {}, base_dir: str,
"""Shows a screen asking to confirm the deletion of a calendar event
"""
nickname = get_nickname_from_actor(path)
+ if not nickname:
+ return None
actor = local_actor_url(http_prefix, nickname, domain_full)
domain, _ = get_domain_from_actor(actor)
message_id = actor + '/statuses/' + post_id
@@ -304,6 +306,8 @@ def html_calendar(person_cache: {}, css_cache: {}, translate: {},
month_number = curr_date.month
nickname = get_nickname_from_actor(actor)
+ if not nickname:
+ return ''
set_custom_background(base_dir, 'calendar-background',
'calendar-background')
diff --git a/webapp_confirm.py b/webapp_confirm.py
index 12e32c64e..7b574ae6f 100644
--- a/webapp_confirm.py
+++ b/webapp_confirm.py
@@ -45,6 +45,8 @@ def html_confirm_delete(css_cache: {},
return None
actor = message_id.split('/statuses/')[0]
nickname = get_nickname_from_actor(actor)
+ if not nickname:
+ return None
domain, port = get_domain_from_actor(actor)
domain_full = get_full_domain(domain, port)
@@ -119,6 +121,8 @@ def html_confirm_remove_shared_item(css_cache: {}, translate: {},
"""Shows a screen asking to confirm the removal of a shared item
"""
nickname = get_nickname_from_actor(actor)
+ if not nickname:
+ return None
domain, port = get_domain_from_actor(actor)
domain_full = get_full_domain(domain, port)
shares_file = \
@@ -207,10 +211,11 @@ def html_confirm_follow(css_cache: {}, translate: {}, base_dir: str,
follow_str += ' \n'
follow_str += \
'
\n'
- follow_str += \
- ' ' + translate['Follow'] + ' ' + \
- get_nickname_from_actor(follow_actor) + \
- '@' + follow_domain + ' ?
\n'
+ follow_actor_nick = get_nickname_from_actor(follow_actor)
+ if follow_actor_nick:
+ follow_str += \
+ ' ' + translate['Follow'] + ' ' + \
+ follow_actor_nick + '@' + follow_domain + ' ?
\n'
follow_str += '
'
- result_str = remove_text_formatting(test_str)
+ result_str = remove_text_formatting(test_str, False)
assert result_str == 'Text with formatting
'
diff --git a/webapp_post.py b/webapp_post.py
index 7b2038f04..567bdf322 100644
--- a/webapp_post.py
+++ b/webapp_post.py
@@ -1604,7 +1604,7 @@ def individual_post_as_html(signing_priv_key_pem: str,
system_language,
domain_full, person_cache,
signing_priv_key_pem,
- blocked_cache)
+ blocked_cache, bold_reading)
if not post_json_announce:
# if the announce could not be downloaded then mark it as rejected
announced_post_id = remove_id_ending(post_json_object['id'])
@@ -1987,20 +1987,18 @@ def individual_post_as_html(signing_priv_key_pem: str,
_log_post_timing(enable_timing_log, post_start_time, '16')
- print('Test bold_reading 1 ' + str(bold_reading))
if not is_pgp_encrypted(content_str):
if not is_patch:
# Add bold text
- print('Test bold_reading 2 ' + str(bold_reading))
if bold_reading and \
not displaying_ciphertext and \
not post_is_blog:
content_str = bold_reading_string(content_str)
- print('Test bold_reading 3 ' + content_str)
object_content = \
remove_long_words(content_str, 40, [])
- object_content = remove_text_formatting(object_content)
+ object_content = \
+ remove_text_formatting(object_content, bold_reading)
object_content = limit_repeated_words(object_content, 6)
object_content = \
switch_words(base_dir, nickname, domain, object_content)
From 65f26f4046ed27f4c3c7930db92a7865066cdf3c Mon Sep 17 00:00:00 2001
From: Bob Mottram
Date: Thu, 24 Mar 2022 14:45:13 +0000
Subject: [PATCH 17/24] Simplify
---
inbox.py | 14 ++++++--------
1 file changed, 6 insertions(+), 8 deletions(-)
diff --git a/inbox.py b/inbox.py
index 87a6f16f3..09bafacfa 100644
--- a/inbox.py
+++ b/inbox.py
@@ -3350,7 +3350,7 @@ def _inbox_after_initial(server,
cw_lists: {}, lists_enabled: str,
content_license_url: str,
languages_understood: [],
- mitm: bool, bold_reading: bool) -> bool:
+ mitm: bool) -> bool:
""" Anything which needs to be done after initial checks have passed
"""
# if this is a clearnet instance then replace any onion/i2p
@@ -3377,6 +3377,10 @@ def _inbox_after_initial(server,
handle_name = handle.split('@')[0]
+ bold_reading = False
+ if server.bold_reading.get(handle_name):
+ bold_reading = True
+
if _receive_like(recent_posts_cache,
session, handle, is_group,
base_dir, http_prefix,
@@ -4804,11 +4808,6 @@ def run_inbox_queue(server,
mitm = False
if queue_json.get('mitm'):
mitm = True
- bold_reading = False
- bold_reading_filename = \
- base_dir + '/accounts/' + handle + '/.boldReading'
- if os.path.isfile(bold_reading_filename):
- bold_reading = True
_inbox_after_initial(server,
recent_posts_cache,
max_recent_posts,
@@ -4840,8 +4839,7 @@ def run_inbox_queue(server,
default_reply_interval_hrs,
cw_lists, lists_enabled,
content_license_url,
- languages_understood, mitm,
- bold_reading)
+ languages_understood, mitm)
if debug:
pprint(queue_json['post'])
print('Queue: Queue post accepted')
From c7ed2626913f8bc7e0d463a6fe11da19fff78290 Mon Sep 17 00:00:00 2001
From: Bob Mottram
Date: Thu, 24 Mar 2022 14:46:22 +0000
Subject: [PATCH 18/24] Avoid emboldening words containing and
---
content.py | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/content.py b/content.py
index 64da22c89..de7838e39 100644
--- a/content.py
+++ b/content.py
@@ -1349,7 +1349,7 @@ def bold_reading_string(text: str) -> str:
reading_markup = False
if not reading_markup and len(wrd) > 1 and \
'<' not in wrd and '>' not in wrd and \
- not wrd.startswith(':'):
+ '&' not in wrd and not wrd.startswith(':'):
prefix = ''
postfix = ''
From f6da511dbf9a23c0f858fb07c65c54f439774677 Mon Sep 17 00:00:00 2001
From: Bob Mottram
Date: Thu, 24 Mar 2022 14:49:44 +0000
Subject: [PATCH 19/24] Revert "Simplify"
This reverts commit 65f26f4046ed27f4c3c7930db92a7865066cdf3c.
---
inbox.py | 14 ++++++++------
1 file changed, 8 insertions(+), 6 deletions(-)
diff --git a/inbox.py b/inbox.py
index 09bafacfa..87a6f16f3 100644
--- a/inbox.py
+++ b/inbox.py
@@ -3350,7 +3350,7 @@ def _inbox_after_initial(server,
cw_lists: {}, lists_enabled: str,
content_license_url: str,
languages_understood: [],
- mitm: bool) -> bool:
+ mitm: bool, bold_reading: bool) -> bool:
""" Anything which needs to be done after initial checks have passed
"""
# if this is a clearnet instance then replace any onion/i2p
@@ -3377,10 +3377,6 @@ def _inbox_after_initial(server,
handle_name = handle.split('@')[0]
- bold_reading = False
- if server.bold_reading.get(handle_name):
- bold_reading = True
-
if _receive_like(recent_posts_cache,
session, handle, is_group,
base_dir, http_prefix,
@@ -4808,6 +4804,11 @@ def run_inbox_queue(server,
mitm = False
if queue_json.get('mitm'):
mitm = True
+ bold_reading = False
+ bold_reading_filename = \
+ base_dir + '/accounts/' + handle + '/.boldReading'
+ if os.path.isfile(bold_reading_filename):
+ bold_reading = True
_inbox_after_initial(server,
recent_posts_cache,
max_recent_posts,
@@ -4839,7 +4840,8 @@ def run_inbox_queue(server,
default_reply_interval_hrs,
cw_lists, lists_enabled,
content_license_url,
- languages_understood, mitm)
+ languages_understood, mitm,
+ bold_reading)
if debug:
pprint(queue_json['post'])
print('Queue: Queue post accepted')
From 0f2b28ed1fce516d1bf3aecd03b478b3db9efc73 Mon Sep 17 00:00:00 2001
From: Bob Mottram
Date: Thu, 24 Mar 2022 14:59:41 +0000
Subject: [PATCH 20/24] Unquote text
---
content.py | 1 +
1 file changed, 1 insertion(+)
diff --git a/content.py b/content.py
index de7838e39..81b8d107e 100644
--- a/content.py
+++ b/content.py
@@ -1331,6 +1331,7 @@ def contains_invalid_local_links(content: str) -> bool:
def bold_reading_string(text: str) -> str:
"""Returns bold reading formatted text
"""
+ text = urllib.parse.unquote(text)
add_paragraph_markup = False
if '' in text:
text = text.replace('
', '\n').replace('', '')
From bca1f1c5b703d527c119185ae9c7ab643b60ca88 Mon Sep 17 00:00:00 2001
From: Bob Mottram
Date: Thu, 24 Mar 2022 15:15:53 +0000
Subject: [PATCH 21/24] Unescape before adding bold
---
content.py | 3 ++-
tests.py | 8 ++++++++
2 files changed, 10 insertions(+), 1 deletion(-)
diff --git a/content.py b/content.py
index 81b8d107e..c649e7fa8 100644
--- a/content.py
+++ b/content.py
@@ -7,6 +7,7 @@ __email__ = "bob@libreserver.org"
__status__ = "Production"
__module_group__ = "Core"
+import html
import os
import email.parser
import urllib.parse
@@ -1331,7 +1332,7 @@ def contains_invalid_local_links(content: str) -> bool:
def bold_reading_string(text: str) -> str:
"""Returns bold reading formatted text
"""
- text = urllib.parse.unquote(text)
+ text = html.unescape(text)
add_paragraph_markup = False
if '' in text:
text = text.replace('
', '\n').replace('', '')
diff --git a/tests.py b/tests.py
index d377161d7..7cc08206a 100644
--- a/tests.py
+++ b/tests.py
@@ -6731,6 +6731,14 @@ def _test_bold_reading() -> None:
print(text_bold)
assert text_bold == expected
+ text = "There's some quoted text here"
+ text_bold = bold_reading_string(text)
+ expected = \
+ "There's some quoted text here"
+ if text_bold != expected:
+ print(text_bold)
+ assert text_bold == expected
+
def run_all_tests():
base_dir = os.getcwd()
From 9fdca7919c9fd1d035117c60d1b713ae5f07a061 Mon Sep 17 00:00:00 2001
From: Bob Mottram
Date: Thu, 24 Mar 2022 15:32:37 +0000
Subject: [PATCH 22/24] Improve handling of markup while emboldening text
---
content.py | 4 ++--
tests.py | 6 +++---
2 files changed, 5 insertions(+), 5 deletions(-)
diff --git a/content.py b/content.py
index c649e7fa8..0bf1f9273 100644
--- a/content.py
+++ b/content.py
@@ -1345,9 +1345,9 @@ def bold_reading_string(text: str) -> str:
new_parag = ''
reading_markup = False
for wrd in words:
- if '<' in wrd and '>' not in wrd:
+ if '<' in wrd:
reading_markup = True
- if reading_markup and '>' in wrd and '<' not in wrd:
+ if reading_markup and '>' in wrd:
reading_markup = False
if not reading_markup and len(wrd) > 1 and \
'<' not in wrd and '>' not in wrd and \
diff --git a/tests.py b/tests.py
index 7cc08206a..98d4e4d4a 100644
--- a/tests.py
+++ b/tests.py
@@ -6721,12 +6721,12 @@ def _test_bold_reading() -> None:
assert text_bold == expected
text = 'This is a test with markup containing spaces
'
+ 'href="some_url">
'
text_bold = bold_reading_string(text)
expected = \
'
This is a test ' + \
- 'with ' + \
- 'markup containing spaces
'
+ '
'
if text_bold != expected:
print(text_bold)
assert text_bold == expected
From 2c087d5e2aed61300bc04ed2627355ba9a05a0ee Mon Sep 17 00:00:00 2001
From: Bob Mottram
Date: Thu, 24 Mar 2022 15:57:44 +0000
Subject: [PATCH 23/24] Another unit test for markup with bold reading
---
content.py | 5 ++++-
tests.py | 14 ++++++++++++++
2 files changed, 18 insertions(+), 1 deletion(-)
diff --git a/content.py b/content.py
index 0bf1f9273..387ec7b59 100644
--- a/content.py
+++ b/content.py
@@ -1351,7 +1351,8 @@ def bold_reading_string(text: str) -> str:
reading_markup = False
if not reading_markup and len(wrd) > 1 and \
'<' not in wrd and '>' not in wrd and \
- '&' not in wrd and not wrd.startswith(':'):
+ '&' not in wrd and '=' not in wrd and \
+ not wrd.startswith(':'):
prefix = ''
postfix = ''
@@ -1370,6 +1371,8 @@ def bold_reading_string(text: str) -> str:
new_parag += wrd + ' '
parag_ctr += 1
new_parag = new_parag.strip()
+ if not new_parag:
+ continue
if parag_ctr < len(paragraphs):
if not add_paragraph_markup:
new_text += new_parag + '\n'
diff --git a/tests.py b/tests.py
index 98d4e4d4a..5bdbb364e 100644
--- a/tests.py
+++ b/tests.py
@@ -6739,6 +6739,20 @@ def _test_bold_reading() -> None:
print(text_bold)
assert text_bold == expected
+ text = '@Someone or other' + \
+ ' some text
'
+ text_bold = bold_reading_string(text)
+ expected = \
+ '' + \
+ '@Someone or other' + \
+ ' some text
'
+ if text_bold != expected:
+ print(text_bold)
+ assert text_bold == expected
+
def run_all_tests():
base_dir = os.getcwd()
From 5b480dd815429592af2b25a52df49e27c9d7d98c Mon Sep 17 00:00:00 2001
From: Bob Mottram
Date: Thu, 24 Mar 2022 16:16:36 +0000
Subject: [PATCH 24/24] Round up word division for bold reading
---
content.py | 8 +++++---
tests.py | 10 +++++-----
2 files changed, 10 insertions(+), 8 deletions(-)
diff --git a/content.py b/content.py
index 387ec7b59..134d32619 100644
--- a/content.py
+++ b/content.py
@@ -7,6 +7,7 @@ __email__ = "bob@libreserver.org"
__status__ = "Production"
__module_group__ = "Core"
+import math
import html
import os
import email.parser
@@ -1349,7 +1350,8 @@ def bold_reading_string(text: str) -> str:
reading_markup = True
if reading_markup and '>' in wrd:
reading_markup = False
- if not reading_markup and len(wrd) > 1 and \
+ wrd_len = len(wrd)
+ if not reading_markup and wrd_len > 1 and \
'<' not in wrd and '>' not in wrd and \
'&' not in wrd and '=' not in wrd and \
not wrd.startswith(':'):
@@ -1361,9 +1363,9 @@ def bold_reading_string(text: str) -> str:
wrd = wrd[1:]
if wrd.endswith('"'):
postfix = '"'
- wrd = wrd[:len(wrd) - 1]
+ wrd = wrd[:wrd_len - 1]
- initial_chars = int(len(wrd) / 2)
+ initial_chars = int(math.ceil(wrd_len / 2.0))
new_parag += \
prefix + '' + wrd[:initial_chars] + '' + \
wrd[initial_chars:] + postfix + ' '
diff --git a/tests.py b/tests.py
index 5bdbb364e..53f197d1c 100644
--- a/tests.py
+++ b/tests.py
@@ -6703,7 +6703,7 @@ def _test_bold_reading() -> None:
text_bold = bold_reading_string(text)
expected = \
"This is a test of " + \
- "emboldening with paragraph.
"
+ "emboldening with paragraph.
"
if text_bold != expected:
print(text_bold)
assert text_bold == expected
@@ -6714,8 +6714,8 @@ def _test_bold_reading() -> None:
text_bold = bold_reading_string(text)
expected = \
"This is a test of " + \
- "emboldening
With more " + \
- "than one paragraph.
"
+ "emboldeningWith more " + \
+ "than one paragraph.
"
if text_bold != expected:
print(text_bold)
assert text_bold == expected
@@ -6731,10 +6731,10 @@ def _test_bold_reading() -> None:
print(text_bold)
assert text_bold == expected
- text = "There's some quoted text here"
+ text = "There's the quoted text here"
text_bold = bold_reading_string(text)
expected = \
- "There's some quoted text here"
+ "There's the quoted text here"
if text_bold != expected:
print(text_bold)
assert text_bold == expected