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

feat: domain validator check scheme #110

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
6 changes: 1 addition & 5 deletions src/Validator/Domain.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,7 @@ public function isValid($value): bool
return false;
}

if (\filter_var($value, FILTER_VALIDATE_DOMAIN) === false) {
return false;
}

return true;
return \filter_var($value, FILTER_VALIDATE_DOMAIN, FILTER_FLAG_HOSTNAME) !== false;
}

/**
Expand Down
9 changes: 7 additions & 2 deletions tests/Validator/DomainTest.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* Utopia PHP Framework
*
Expand Down Expand Up @@ -30,13 +31,17 @@ public function testIsValid()
$this->assertEquals(true, $this->domain->isValid('example.com'));
$this->assertEquals(true, $this->domain->isValid('subdomain.example.com'));
$this->assertEquals(true, $this->domain->isValid('subdomain.example-app.com'));
$this->assertEquals(true, $this->domain->isValid('subdomain.example_app.com'));
$this->assertEquals(true, $this->domain->isValid('subdomain-new.example.com'));
$this->assertEquals(true, $this->domain->isValid('subdomain_new.example.com'));
$this->assertEquals(true, $this->domain->isValid('localhost'));
$this->assertEquals(true, $this->domain->isValid('example.io'));
$this->assertEquals(true, $this->domain->isValid('example.org'));
$this->assertEquals(true, $this->domain->isValid('example.org'));
$this->assertEquals(false, $this->domain->isValid('example.com/path'));
$this->assertEquals(false, $this->domain->isValid('subdomain_new.example.com'));
$this->assertEquals(false, $this->domain->isValid('subdomain.example_app.com'));
stnguyen90 marked this conversation as resolved.
Show resolved Hide resolved
$this->assertEquals(false, $this->domain->isValid('http://example.com'));
$this->assertEquals(false, $this->domain->isValid('https://example.com'));
$this->assertEquals(false, $this->domain->isValid('ftp://example.com'));
$this->assertEquals(false, $this->domain->isValid(false));
$this->assertEquals(false, $this->domain->isValid('.'));
$this->assertEquals(false, $this->domain->isValid('..'));
Expand Down