Page MenuHomeDevCentral

D2282.id5748.diff
No OneTemporary

D2282.id5748.diff

diff --git a/src/HTTP/URL.php b/src/HTTP/URL.php
new file mode 100644
--- /dev/null
+++ b/src/HTTP/URL.php
@@ -0,0 +1,23 @@
+<?php
+
+namespace Keruald\OmniTools\HTTP;
+
+class URL {
+
+ public static function normalizeQuery (string $query) : string {
+ return rawurlencode($query);
+ }
+
+ public static function beautifyQuery (string $query) : string {
+ return rawurldecode($query);
+ }
+
+ public static function normalizeDomain (string $domain) : string {
+ return idn_to_ascii($domain, 0, INTL_IDNA_VARIANT_UTS46);
+ }
+
+ public static function beautifyDomain (string $domain) : string {
+ return idn_to_utf8($domain, 0, INTL_IDNA_VARIANT_UTS46);
+ }
+
+}
diff --git a/tests/HTTP/URL.php b/tests/HTTP/URL.php
new file mode 100644
--- /dev/null
+++ b/tests/HTTP/URL.php
@@ -0,0 +1,27 @@
+<?php
+declare(strict_types=1);
+
+namespace Keruald\OmniTools\Tests\HTTP;
+
+use Keruald\OmniTools\HTTP\URL;
+use PHPUnit\Framework\TestCase;
+
+class URLTest extends TestCase {
+
+ /**
+ * @dataProvider provideDomainsAndURLs
+ */
+ public function testGetDomain ($url, $expectedDomain) : void {
+ $url = new URL($url);
+
+ $this->assertEquals($expectedDomain, ($url->getDomain());
+ }
+
+ public function provideDomainsAndURLs () : iterable {
+ yield ["http://foo/bar", "foo"];
+ yield ["https://xn--dghrefn-mxa.nasqueron.org/", "dæghrefn.nasqueron.org"];
+ yield ["://foo/bar", "foo"];
+ yield ["/bar", ""];
+ }
+
+}

File Metadata

Mime Type
text/plain
Expires
Tue, Apr 22, 13:27 (15 h, 55 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2595574
Default Alt Text
D2282.id5748.diff (1 KB)

Event Timeline