Add entity escaping to URLs

This commit is contained in:
Daniil Gentili 2024-05-07 15:11:17 +02:00
parent d70207fdbb
commit 73dd84277d
2 changed files with 16 additions and 4 deletions

View File

@ -376,7 +376,7 @@ final class Entities
'italic' => '<i>', 'italic' => '<i>',
'code' => '<code>', 'code' => '<code>',
'pre' => isset($entity['language']) && $entity['language'] !== '' ? '<pre language="'.$entity['language'].'">' : '<pre>', 'pre' => isset($entity['language']) && $entity['language'] !== '' ? '<pre language="'.$entity['language'].'">' : '<pre>',
'text_link' => '<a href="'.$entity['url'].'">', 'text_link' => '<a href="'.EntityTools::htmlEscape($entity['url']).'">',
'strikethrough' => '<s>', 'strikethrough' => '<s>',
"underline" => '<u>', "underline" => '<u>',
"block_quote" => '<blockquote>', "block_quote" => '<blockquote>',

View File

@ -293,6 +293,18 @@ class EntitiesTest extends TestCase
]] ]]
]; ];
yield [
'test',
'<a href="https://google.com/?arg=a&amp;arg2=b">test</a>',
'<a href="https://google.com/?arg=a&amp;arg2=b">test</a>',
[[
'type' => 'text_link',
'offset' => 0,
'length' => 4,
'url' => 'https://google.com/?arg=a&arg2=b',
]]
];
yield [ yield [
'test', 'test',
'<u>test</u>', '<u>test</u>',
@ -787,17 +799,17 @@ class EntitiesTest extends TestCase
], ],
[ [
'html', 'html',
'<a href="https://google.com/">link </a>', '<a href="https://google.com/?a=a&amp;b=b">link </a>',
'link', 'link',
[ [
[ [
'offset' => 0, 'offset' => 0,
'length' => 4, 'length' => 4,
'type' => 'text_link', 'type' => 'text_link',
'url' => 'https://google.com/', 'url' => 'https://google.com/?a=a&b=b',
], ],
], ],
'<a href="https://google.com/">link</a> ', '<a href="https://google.com/?a=a&amp;b=b">link</a> ',
], ],
[ [
'markdown', 'markdown',