Browse Source

Fix url input and mark it as required

Validation is done in html on the client
and raises an error 400 in the api.

This fixes #2.
sqozz 1 year ago
parent
commit
154df1af2b
2 changed files with 3 additions and 1 deletions
  1. 2
    0
      schort.py
  2. 1
    1
      templates/index.html

+ 2
- 0
schort.py View File

@@ -38,6 +38,8 @@ def short(shortLink=""):
38 38
 	elif request.method == "POST": # Someone submitted a new link to short
39 39
 		longUrl = request.form["url"] # required, accept the exception if the key does not exist
40 40
 		wishId = request.form.get("wishId")
41
+		if len(longUrl) <= 0:
42
+			abort(400)
41 43
 		databaseId = insertIdUnique(longUrl, idToCheck=wishId)
42 44
 		return request.url_root + databaseId # Short link in plain text
43 45
 

+ 1
- 1
templates/index.html View File

@@ -12,7 +12,7 @@
12 12
 			</div>
13 13
 			<form action="/" method="post" id="short_form">
14 14
 				<span id="url_text">URL:</span>
15
-				<input type="input" name="url" id="url_input">
15
+				<input type="url" name="url" id="url_input" required>
16 16
 				<input type="hidden" name="wishId" value="{{name}}">
17 17
 				<input type="submit" value="Schort!" id="short_button">
18 18
 			</form>

Loading…
Cancel
Save