Skip to content
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

Improve url validation and refactor test code #331

Merged
merged 1 commit into from
Jul 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 14 additions & 11 deletions src/basolato/core/validation.nim
Original file line number Diff line number Diff line change
Expand Up @@ -641,20 +641,23 @@ proc url(value:string):bool =
if not protocolList.contains(protocol):
return false

var domainStr = value.split("://")[1].split("/")[0]
if domainStr.contains(":"):
let port = domainStr.split(":")[1]
if not port.numeric():
try:
var domainStr = value.split("://")[1].split("/")[0]
if domainStr.contains(":"):
let port = domainStr.split(":")[1]
if not port.numeric():
return false
domainStr = domainStr.split(":")[0]
if not domain(domainStr):
return false
domainStr = domainStr.split(":")[0]
if not domain(domainStr):
return false

let path = value.split("://")[1].split("/")[1..^1].join("/")
let reg = re"^(?:[\pL\pN\-._\~!$&\'()*+,;=:@\/?]|%[0-9A-Fa-f]{2})*$"
if not path.match(reg):
let path = value.split("://")[1].split("/")[1..^1].join("/")
let reg = re"^(?:[\pL\pN\-._\~!$&\'()*+,;=:@\/?]|%[0-9A-Fa-f]{2})*$"
if not path.match(reg):
return false
return true
except:
return false
return true

proc url*(self:Validation, value:string):bool =
return url(value)
Expand Down
Loading
Loading