Bugfix: json parsing error handling

pull/12/head 0.3.1
Cesura 4 years ago
parent d75ade2401
commit 683143d7ad

@ -6,7 +6,7 @@ from os import environ
from distutils.util import strtobool from distutils.util import strtobool
from threading import Thread from threading import Thread
pastey_version = "0.3" pastey_version = "0.3.1"
loaded_config = {} loaded_config = {}
loaded_themes = [] loaded_themes = []
@ -45,6 +45,7 @@ if __name__ == "__main__":
print("Pastey version ", pastey_version) print("Pastey version ", pastey_version)
print("USING THE FOLLOWING CONFIGURATION:") print("USING THE FOLLOWING CONFIGURATION:")
print("=====================================") print("=====================================")
loaded_config['pastey_version'] = pastey_version
for option in dir(config): for option in dir(config):
if not option.startswith("__"): if not option.startswith("__"):
loaded_config[option] = eval("config.%s" % option) loaded_config[option] = eval("config.%s" % option)

@ -18,14 +18,21 @@ def get_recent(limit=config.recent_pastes):
recent_pastes = [] recent_pastes = []
i = 0 i = 0
while i < limit and i < len(paths): while i < limit and i < len(paths):
if paths[i].is_file():
with open(paths[i]) as fp: with open(paths[i]) as fp:
try:
paste = json.loads(fp.read()) paste = json.loads(fp.read())
except json.JSONDecodeError:
i += 1
continue
# Set extra metadata
basename = path.basename(paths[i]) basename = path.basename(paths[i])
paste['unique_id'] = basename[:-8] if basename.endswith(".expires") else basename paste['unique_id'] = basename[:-8] if basename.endswith(".expires") else basename
paste['content'] = '\n'.join(paste['content'].splitlines()[0:10]) paste['content'] = '\n'.join(paste['content'].splitlines()[0:10])
paste['icon'] = common.get_icon(paste['language']) paste['icon'] = common.get_icon(paste['language'])
# Replace preview if encrypted
if paste['encrypted']: if paste['encrypted']:
paste['content'] = "[Encrypted]" paste['content'] = "[Encrypted]"
@ -40,7 +47,10 @@ def get_paste(unique_id, key=""):
if file_path is not None: if file_path is not None:
with open(file_path, "r") as fp: with open(file_path, "r") as fp:
try:
paste = json.loads(fp.read()) paste = json.loads(fp.read())
except json.JSONDecodeError:
return None
# Check if paste is expired # Check if paste is expired
if common.is_expired(paste): if common.is_expired(paste):

@ -1,4 +1,4 @@
flask Flask==1.1.2
Flask-Limiter==1.4 Flask-Limiter==1.4
guesslang guesslang==2.0.1
cryptography cryptography==3.4.7
Loading…
Cancel
Save