Skip to content

Commit

Permalink
Add entity escaping to URLs
Browse files Browse the repository at this point in the history
  • Loading branch information
danog committed May 7, 2024
1 parent d70207f commit 73dd842
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/Entities.php
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ public function toHTML(bool $allowTelegramTags = false): string
'italic' => '<i>',
'code' => '<code>',
'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>',
"underline" => '<u>',
"block_quote" => '<blockquote>',
Expand Down
18 changes: 15 additions & 3 deletions tests/EntitiesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,18 @@ public static function provideHtmlEntities(): iterable
]]
];

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 [
'test',
'<u>test</u>',
Expand Down Expand Up @@ -787,17 +799,17 @@ private function provideEntities(): array
],
[
'html',
'<a href="https://google.com/">link </a>',
'<a href="https://google.com/?a=a&amp;b=b">link </a>',
'link',
[
[
'offset' => 0,
'length' => 4,
'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',
Expand Down

0 comments on commit 73dd842

Please sign in to comment.