handling spaces better

This commit is contained in:
Jarian Cottingham 2025-10-17 01:39:15 -05:00
parent 8a630e7ba3
commit 3c2073614f
2 changed files with 21 additions and 13 deletions

View File

@ -194,29 +194,37 @@ def article_content_endpoint():
if not file_path:
return jsonify({"error": "Missing 'path' parameter"}), 400
# URL decode the file path to handle spaces and special characters properly
import urllib.parse
decoded_file_path = urllib.parse.unquote(file_path)
# Validate that the file exists and is within our article directory
# We'll ensure the file path is safe by checking it's under ARTICLE_DIR
file_path = os.path.abspath(file_path)
article_dir = os.path.abspath(ARTICLE_DIR)
try:
decoded_file_path = os.path.abspath(decoded_file_path)
article_dir = os.path.abspath(ARTICLE_DIR)
if not file_path.startswith(article_dir):
return jsonify(
{"error": "Invalid file path - must be within article directory"}
), 400
if not decoded_file_path.startswith(article_dir):
return jsonify(
{"error": "Invalid file path - must be within article directory"}
), 400
if not os.path.exists(file_path):
return jsonify({"error": "Article file not found"}), 404
if not os.path.exists(decoded_file_path):
return jsonify({"error": "Article file not found"}), 404
except Exception as e:
return jsonify({"error": f"Path validation failed: {str(e)}"}), 400
# Read the content of the article file
with open(file_path, "r", encoding="utf-8") as f:
with open(decoded_file_path, "r", encoding="utf-8") as f:
content = f.read()
# Get basic info about the article
outlet = os.path.basename(os.path.dirname(file_path))
filename = os.path.basename(file_path)
outlet = os.path.basename(os.path.dirname(decoded_file_path))
filename = os.path.basename(decoded_file_path)
response_data = {
"path": file_path,
"path": decoded_file_path,
"name": filename,
"outlet": outlet,
"content": content,

View File

@ -13,4 +13,4 @@ if __name__ == "__main__":
if "ARTICLE_DIR" not in os.environ:
print("Warning: ARTICLE_DIR environment variable not set. Using default path.")
app.run(host="0.0.0.0", port=5000, debug=True)
app.run(host="0.0.0.0", port=5008, debug=True)