Skip to content

Commit 37417e5

Browse files
shiwani42northdpole
authored andcommitted
fix: return 400 when text param is missing in text_search
Closes #862 request.args.get('text') returns None if the query param is absent. Passing None into db.text_search() causes re.search() to raise TypeError: expected string or bytes-like object. Return a 400 before reaching the database call.
1 parent fc72d69 commit 37417e5

2 files changed

Lines changed: 8 additions & 0 deletions

File tree

application/tests/web_main_test.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -452,6 +452,12 @@ def test_test_search(self) -> None:
452452
collection.add_node(docs["sa"])
453453

454454
with self.app.test_client() as client:
455+
response = client.get("/rest/v1/text_search")
456+
self.assertEqual(400, response.status_code)
457+
458+
response = client.get("/rest/v1/text_search?text=")
459+
self.assertEqual(400, response.status_code)
460+
455461
response = client.get(f"/rest/v1/text_search?text='CRE:2'")
456462
self.assertEqual(404, response.status_code)
457463

application/web/web_main.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -559,6 +559,8 @@ def text_search() -> Any:
559559
"""
560560
database = db.Node_collection()
561561
text = request.args.get("text")
562+
if not text:
563+
return jsonify({"error": "text parameter is required"}), 400
562564
if posthog:
563565
posthog.capture(f"text_search", f"text:{text}")
564566

0 commit comments

Comments
 (0)