Skip to content

Commit c74bc6e

Browse files
authored
Merge pull request #16 from arnt/idn-support
IDN support
2 parents 7a166ef + 023427c commit c74bc6e

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

src/Autolink.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ public function convert(string $text, array $attribs = []): string
9797

9898
$schemeRegex = sprintf($schemeRegex, $this->getSchemes(true));
9999

100-
$regex = '/(([a-zA-Z]*=")*' . $schemeRegex . "[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,3}([\/a-zA-Z0-9\-._~:?#\[\]@!$&'()*+,;=%\">]*)?)/";
100+
$regex = '/(([a-zA-Z]*=")*' . $schemeRegex . "[\-\p{L}\p{N}\p{M}]+\.[\p{L}\p{M}]{2,}([\/\p{L}\p{N}\p{M}\-._~:?#\[\]@!$&'()*+,;=%\">]*)?)/u";
101101

102102
return preg_replace_callback(
103103
$regex,

test/AutolinkTest.php

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,10 @@ public function testConvert()
6262
6363
This is URL inline: http://example.com/path#top with test.
6464
65+
This is an IDN URL: http://dømi.fo
66+
67+
This is an IDN URL in Devanagari: http://सार्वभौमिक-स्वीकृति-परीक्षण.संगठन
68+
6569
This is URL in HTML:
6670
<a href="http://example.com/path?foo[1]=a&foo[2]=b">LINK</a>
6771
<a href="http://example.com/path?foo[1]=a&foo[2]=b">http://example.com/path?foo[1]=a&foo[2]=b</a>
@@ -92,6 +96,10 @@ public function testConvert()
9296
9397
This is URL inline: <a href="http://example.com/path#top">http://example.com/path#top</a> with test.
9498
99+
This is an IDN URL: <a href="http://dømi.fo">http://dømi.fo</a>
100+
101+
This is an IDN URL in Devanagari: <a href="http://सार्वभौमिक-स्वीकृति-परीक्षण.संगठन">http://सार्वभौमिक-स्वीकृति-परीक्षण.संगठन</a>
102+
95103
This is URL in HTML:
96104
<a href="http://example.com/path?foo[1]=a&foo[2]=b">LINK</a>
97105
<a href="http://example.com/path?foo[1]=a&foo[2]=b">http://example.com/path?foo[1]=a&foo[2]=b</a>
@@ -239,6 +247,15 @@ public function testLinkNoScheme()
239247
$this->instance->addScheme('skype');
240248

241249
self::assertEquals('<a href="' . $url . '">' . $url . '</a>', $this->instance->convert($url));
250+
251+
$url = 'dømi.fo';
252+
253+
self::assertEquals('<a href="http://' . $url . '">' . $url . '</a>', $this->instance->convert($url));
254+
255+
$url = 'dømi.fo/dømi';
256+
257+
self::assertEquals('<a href="http://' . $url . '">' . $url . '</a>', $this->instance->convert($url));
258+
242259
}
243260

244261
/**
@@ -310,7 +327,7 @@ public function testConvertEmail()
310327
311328
My email address is [email protected].
312329
313-
and emails are coming in between([email protected]).
330+
and emails are coming in between([email protected]).
314331
TEXT;
315332

316333
$html = <<<HTML

0 commit comments

Comments
 (0)