Thanks to visit codestin.com
Credit goes to github.com

Skip to content
This repository was archived by the owner on Apr 14, 2025. It is now read-only.

Commit 732eaec

Browse files
committed
Merge pull request #22 from jeremykendall/fix/issue-20
Updates parser to allow for more accurate URL parsing
2 parents 26d6a6f + 7dae0e0 commit 732eaec

3 files changed

Lines changed: 11 additions & 3 deletions

File tree

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,6 @@
1313
},
1414
"require": {
1515
"php": ">=5.3.0",
16-
"jeremykendall/php-domain-parser": "0.0.8"
16+
"jeremykendall/php-domain-parser": "1.*"
1717
}
1818
}

src/Purl/Parser.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,15 @@ public function parseUrl($url)
6060
$url = (string) $url;
6161
}
6262

63-
$result = parse_url($url);
63+
$result = false;
64+
65+
// If there's a single leading forward slash, use parse_url()
66+
if (preg_match('#^\/{1}[^\/]#', $url) === 1) {
67+
$result = parse_url($url);
68+
} else {
69+
// Otherwise use the PSL parser
70+
$result = $this->pslParser->parseUrl($url)->toArray();
71+
}
6472

6573
if ($result === false) {
6674
throw new \InvalidArgumentException(sprintf('Invalid url %s', $url));

src/Purl/ParserInterface.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
/*
3+
/**
44
* This file is part of the Purl package, a project by Jonathan H. Wage.
55
*
66
* (c) 2013 Jonathan H. Wage

0 commit comments

Comments
 (0)