aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJan-Hendrik Willms <tleilax+studip@gmail.com>2024-05-15 19:20:45 +0000
committerJan-Hendrik Willms <tleilax+studip@gmail.com>2024-05-15 19:20:45 +0000
commit6899773092a6b73ab053be884a94033894aeb5e4 (patch)
treeee3e8127672681f9a65f9bb2cb96d793581308cf
parent9cdccef4cfc8cc02af4897c17b7a9572f96529fa (diff)
update algo26-matthias/idna-convert v4.0.2, remove bogus code and add test, fixes #4149
Closes #4149 Merge request studip/studip!2989
-rw-r--r--composer.json2
-rw-r--r--composer.lock18
-rw-r--r--lib/visual.inc.php39
-rw-r--r--tests/unit/lib/VisualTest.php11
4 files changed, 40 insertions, 30 deletions
diff --git a/composer.json b/composer.json
index 873ec70..0d346cf 100644
--- a/composer.json
+++ b/composer.json
@@ -28,7 +28,7 @@
"jasig/phpcas": "1.5",
"phpxmlrpc/phpxmlrpc": "^4.9.0",
"phpxmlrpc/extras": "^1.0.0-beta2",
- "algo26-matthias/idna-convert": "^3.0",
+ "algo26-matthias/idna-convert": "4.0.2",
"caxy/php-htmldiff": "0.1.15",
"phpseclib/phpseclib": "3.0.37",
"ext-gd": "*",
diff --git a/composer.lock b/composer.lock
index 30a54d9..a181ed1 100644
--- a/composer.lock
+++ b/composer.lock
@@ -4,29 +4,29 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
- "content-hash": "0eef2a184f508c6e49337786eb186fca",
+ "content-hash": "7f21be4fc85b3802bbef600b7cc4c538",
"packages": [
{
"name": "algo26-matthias/idna-convert",
- "version": "v3.1.0",
+ "version": "v4.0.2",
"source": {
"type": "git",
"url": "https://github.com/algo26-matthias/idna-convert.git",
- "reference": "340a4dc65f6b0d9884853a3d32895d82f0c1502a"
+ "reference": "254938fb52b8bd34053401695d749f0e73fbb503"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/algo26-matthias/idna-convert/zipball/340a4dc65f6b0d9884853a3d32895d82f0c1502a",
- "reference": "340a4dc65f6b0d9884853a3d32895d82f0c1502a",
+ "url": "https://api.github.com/repos/algo26-matthias/idna-convert/zipball/254938fb52b8bd34053401695d749f0e73fbb503",
+ "reference": "254938fb52b8bd34053401695d749f0e73fbb503",
"shasum": ""
},
"require": {
"ext-pcre": "*",
"jakeasmith/http_build_url": "^1",
- "php": ">=7.2.0"
+ "php": ">=8.1"
},
"require-dev": {
- "phpunit/phpunit": "8.0"
+ "phpunit/phpunit": "^9 || ^10"
},
"suggest": {
"ext-iconv": "Install ext/iconv for using input / output other than UTF-8 or ISO-8859-1",
@@ -58,9 +58,9 @@
],
"support": {
"issues": "https://github.com/algo26-matthias/idna-convert/issues",
- "source": "https://github.com/algo26-matthias/idna-convert/tree/v3.1.0"
+ "source": "https://github.com/algo26-matthias/idna-convert/tree/v4.0.2"
},
- "time": "2023-02-17T10:08:02+00:00"
+ "time": "2024-02-14T13:30:05+00:00"
},
{
"name": "caxy/php-htmldiff",
diff --git a/lib/visual.inc.php b/lib/visual.inc.php
index 2ddcd46..86efbfb 100644
--- a/lib/visual.inc.php
+++ b/lib/visual.inc.php
@@ -290,31 +290,30 @@ function isLinkIntern($url) {
}
/**
-* convert links with 'umlauten' to punycode
-*
-* @access public
-* @param string link to convert
-* @param boolean for mailadr = true and for other link = false
-* @return string link in punycode
-*/
-function idna_link($link, $mail = false) {
+ * convert links with 'umlauten' to punycode
+ *
+ * @param string $link link to convert
+ * @return string link in punycode
+ *
+ * @throws \Algo26\IdnaConvert\Exception\AlreadyPunycodeException
+ * @throws \Algo26\IdnaConvert\Exception\InvalidCharacterException
+ */
+function idna_link(string $link) {
if (!Config::get()->CONVERT_IDNA_URL) {
return $link;
}
- $pu = @parse_url($link);
- if (isset($pu['host']) && preg_match('/&\w+;/i', $pu['host'])) { //umlaute? (html-coded)
+
+ $pu = parse_url($link);
+ if (
+ isset($pu['host'])
+ && preg_match('/&\w+;/i', $pu['host']) //umlaute? (html-coded)
+ && preg_match('#^([^/]*)//([^/?]*)([/?].*)?$#i',$link, $matches)
+ ) {
$IDN = new Algo26\IdnaConvert\ToIdn();
- $out = false;
- if ($mail){
- if (preg_match('#^([^@]*)@(.*)$#i',$link, $matches)) {
- $out = $IDN->convert(decodeHTML($matches[2], ENT_NOQUOTES)); // false by error
- $out = $out ? $matches[1] . '@' . htmlReady($out) : $link;
- }
- } elseif (preg_match('#^([^/]*)//([^/?]*)(((/|\?).*$)|$)#i',$link, $matches)) {
- $out = $IDN->convert(decodeHTML($matches[2], ENT_NOQUOTES)); // false by error
- $out = $out ? $matches[1].'//'.htmlReady($out).$matches[3] : $link;
+ $out = $IDN->convert(decodeHTML($matches[2])); // false by error
+ if ($out) {
+ return $matches[1] . '//' . htmlReady($out) . ($matches[3] ?? '');
}
- return $out ?: $link;
}
return $link;
}
diff --git a/tests/unit/lib/VisualTest.php b/tests/unit/lib/VisualTest.php
index c62cd05..ae9263f 100644
--- a/tests/unit/lib/VisualTest.php
+++ b/tests/unit/lib/VisualTest.php
@@ -21,6 +21,7 @@ class VisualFunctionsTest extends \Codeception\Test\Unit
static $config = [
'LOAD_EXTERNAL_MEDIA' => 'allow',
'OPENGRAPH_ENABLE' => false,
+ 'CONVERT_IDNA_URL' => true,
];
Config::set(new Config($config));
@@ -224,6 +225,16 @@ class VisualFunctionsTest extends \Codeception\Test\Unit
$this->assertEquals($expected, formatReady($input));
}
+ public function testIdnaLink()
+ {
+ $input = htmlentities('https://www.täst-dömäne-mit-ümläuten.de');
+
+ $this->assertEquals(
+ 'https://www.xn--tst-dmne-mit-mluten-gwbfj61b7e.de',
+ idna_link($input)
+ );
+ }
+
private function wrap($string)
{
return sprintf(FORMATTED_CONTENT_WRAPPER, $string);