Skip to content
Closed
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 numberDiff line numberDiff 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 numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
<?php

/**
* Utopia PHP Framework
*
Expand DownExpand 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'));
Comment thread
stnguyen90 marked this conversation as 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