-
Notifications
You must be signed in to change notification settings - Fork 0
handle invalid and valid url #33
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
56704a0
d550988
4707cd3
cb00a8a
6360b2e
c13ea0b
3f6c2de
67bbe8a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,5 @@ | ||
| import os | ||
| import re | ||
| from datetime import datetime, timezone | ||
| from typing import Optional | ||
| from app.utils.cache import list_cache_clean, clear_cache | ||
|
|
@@ -98,12 +99,25 @@ async def create_short_url( | |
| qr_type: str = Form("short"), | ||
| ): | ||
| session = request.session | ||
| original_url = sanitize_url(original_url) | ||
| original_url = original_url.strip() | ||
|
|
||
| if not original_url or not is_valid_url(original_url): | ||
| if not original_url.startswith(("http://", "https://")): | ||
| if re.match(r"^[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+){1,2}$", original_url): | ||
| original_url = "https://" + original_url | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why do you add
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if i don't add this ...then the url like google.com which is valid ,but can't show it as a valid |
||
| else: | ||
| session["error"] = "Please enter a valid URL." | ||
| return RedirectResponse("/", status_code=status.HTTP_303_SEE_OTHER) | ||
|
|
||
| if not is_valid_url(original_url): | ||
| session["error"] = "Please enter a valid URL." | ||
| return RedirectResponse("/", status_code=status.HTTP_303_SEE_OTHER) | ||
|
|
||
| # original_url = sanitize_url(original_url) | ||
|
|
||
| # if not original_url or not is_valid_url(original_url): | ||
| # session["error"] = "Please enter a valid URL." | ||
| # return RedirectResponse("/", status_code=status.HTTP_303_SEE_OTHER) | ||
|
|
||
| short_code: Optional[str] = get_short_from_cache(original_url) | ||
|
|
||
| if not short_code and db.is_connected(): | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is incorrect approach; create separate method and use that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sir if i romve this then if anyone type like https://kdkfjclkdclkd.....it will pass and generate qr ...because it is syntactically valid. ...if u told i will remove it and check only valid urls.