Skip to content
This repository was archived by the owner on Nov 20, 2019. It is now read-only.

Commit 7af40d6

Browse files
Rohaqlayershifter
authored andcommitted
fix(Parser): underscore at end of hostname label causes parsing to fail (#32)
* Allow underscores at end of subdomain labels. * Amended tests for the above.
1 parent 4cbd2e8 commit 7af40d6

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

src/Extract.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ class Extract
5555
* @see https://tools.ietf.org/html/rfc1034
5656
* @see https://tools.ietf.org/html/rfc2181
5757
*/
58-
const HOSTNAME_PATTERN = '#^((?!-)[a-z0-9_-]{0,62}[a-z0-9]\.)+[a-z]{2,63}|[xn\-\-a-z0-9]]{6,63}$#';
58+
const HOSTNAME_PATTERN = '#^((?!-)[a-z0-9_-]{0,62}[a-z0-9_]\.)+[a-z]{2,63}|[xn\-\-a-z0-9]]{6,63}$#';
5959

6060
/**
6161
* @var int Value of extraction options.

tests/ExtractTest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -527,9 +527,19 @@ public function testParseUnderscore()
527527
static::assertEquals('com', $this->extract->parse('dkim._domainkey.example.com')->getSuffix());
528528
static::assertEquals('example', $this->extract->parse('dkim._domainkey.example.com')->getHostname());
529529
static::assertEquals('dkim._domainkey', $this->extract->parse('dkim._domainkey.example.com')->getSubdomain());
530+
static::assertEquals(array('dkim','_domainkey'), $this->extract->parse('dkim._domainkey.example.com')->getSubdomains());
530531

531532
static::assertEquals('com', $this->extract->parse('_spf.example.com')->getSuffix());
532533
static::assertEquals('example', $this->extract->parse('_spf.example.com')->getHostname());
533534
static::assertEquals('_spf', $this->extract->parse('_spf.example.com')->getSubdomain());
535+
536+
static::assertEquals('com', $this->extract->parse('foo_.example.com')->getSuffix());
537+
static::assertEquals('example', $this->extract->parse('foo_.example.com')->getHostname());
538+
static::assertEquals('foo_', $this->extract->parse('foo_.example.com')->getSubdomain());
539+
540+
static::assertEquals('com', $this->extract->parse('bar.foo_.example.com')->getSuffix());
541+
static::assertEquals('example', $this->extract->parse('bar.foo_.example.com')->getHostname());
542+
static::assertEquals('bar.foo_', $this->extract->parse('bar.foo_.example.com')->getSubdomain());
543+
static::assertEquals(array('bar', 'foo_'), $this->extract->parse('bar.foo_.example.com')->getSubdomains());
534544
}
535545
}

0 commit comments

Comments
 (0)