Skip to content

Commit 1d2de31

Browse files
j0k3rjtojnar
authored andcommitted
Replace true/punycode by symfony/polyfill-intl-idn
Because it's no more maintained. (cherry picked from commit 06394db)
1 parent 3a481db commit 1d2de31

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
"simplepie/simplepie": "^1.7",
3232
"smalot/pdfparser": "^1.1",
3333
"symfony/options-resolver": "^3.4|^4.4|^5.3|^6.0|^7.0",
34-
"true/punycode": "^2.1",
34+
"symfony/polyfill-intl-idn": "^1.26",
3535
"guzzlehttp/psr7": "^1.5.0|^2.0"
3636
},
3737
"require-dev": {

src/Graby.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
use Readability\Readability;
2020
use Smalot\PdfParser\Parser as PdfParser;
2121
use Symfony\Component\OptionsResolver\OptionsResolver;
22-
use TrueBV\Punycode;
2322

2423
/**
2524
* @todo add proxy
@@ -39,7 +38,6 @@ class Graby
3938

4039
/** @var ConfigBuilder */
4140
private $configBuilder;
42-
private $punycode;
4341

4442
private $imgNoReferrer = false;
4543
private $prefetchedContent;
@@ -118,8 +116,6 @@ public function __construct($config = [], ?ClientInterface $client = null, ?Conf
118116
$this->config['http_client'],
119117
$this->logger
120118
);
121-
122-
$this->punycode = new Punycode();
123119
}
124120

125121
/**
@@ -495,7 +491,13 @@ private function validateUrl($url)
495491
$uri = new Uri((string) $url);
496492

497493
if (preg_match('/[\x80-\xff]/', $uri->getHost())) {
498-
$uri = $uri->withHost($this->punycode->encode($uri->getHost()));
494+
$uriIdnSafe = idn_to_ascii($uri->getHost());
495+
496+
if (false === $uriIdnSafe) {
497+
throw new \InvalidArgumentException(\sprintf('Url "%s" is not valid IDN to ascii.', $url));
498+
}
499+
500+
$uri = $uri->withHost($uriIdnSafe);
499501
}
500502

501503
if (\strlen($uri->getPath()) && preg_match('/[\x80-\xff]/', $uri->getPath())) {

0 commit comments

Comments
 (0)