Protect link URLs from Telegram inline formatting
Build custom container images / build (map[base_image:php:8-fpm-alpine build_args:PHP_VERSION=8
context:php8-pgsql fingerprint_command:{ apk info -v | LC_ALL=C sort; find /usr/local/lib/php/extensions /usr/local/etc/php/conf.d -type f -exec sha256sum {} + | LC_ALL=C sort; }
name:ph… (push) Successful in 39s
Build custom container images / build (map[base_image:postgres:18 build_args:PG_VERSION=18
POSTGIS_VERSION=3
VCHORD_VERSION=0.5.3
context:postgres fingerprint_command:{ dpkg-query -W -f='${binary:Package}=${Version}\n' | LC_ALL=C sort; find /usr/lib/postgresql -type f -exec sha256su… (push) Successful in 48s
Build custom container images / build (map[base_image:python:3 build_args:PYTHON_VERSION=3
context:python-tools fingerprint_command:{ dpkg-query -W -f='${binary:Package}=${Version}\n' | LC_ALL=C sort; pip freeze | LC_ALL=C sort; }
name:python-tools oci_labels:org.opencontainers.ima… (push) Failing after 1m48s
Build custom container images / build (map[base_image:python:3.12-slim build_args:PYTHON_VERSION=3.12-slim
context:linkki-tiedotus fingerprint_command:{ dpkg-query -W -f='${binary:Package}=${Version}\n' | LC_ALL=C sort; pip freeze | LC_ALL=C sort; }
name:linkki-tiedotus oci_labels:… (push) Successful in 26s
Build custom container images / build (map[base_image:python:3.12-slim build_args:PYTHON_VERSION=3.12-slim
context:timepoll fingerprint_command:{ dpkg-query -W -f='${binary:Package}=${Version}\n' | LC_ALL=C sort; pip freeze | LC_ALL=C sort; }
name:timepoll oci_labels:org.opencontai… (push) Successful in 34s
Build custom container images / build (map[base_image:php:8-fpm-alpine build_args:PHP_VERSION=8
context:php8-pgsql fingerprint_command:{ apk info -v | LC_ALL=C sort; find /usr/local/lib/php/extensions /usr/local/etc/php/conf.d -type f -exec sha256sum {} + | LC_ALL=C sort; }
name:ph… (push) Successful in 39s
Build custom container images / build (map[base_image:postgres:18 build_args:PG_VERSION=18
POSTGIS_VERSION=3
VCHORD_VERSION=0.5.3
context:postgres fingerprint_command:{ dpkg-query -W -f='${binary:Package}=${Version}\n' | LC_ALL=C sort; find /usr/lib/postgresql -type f -exec sha256su… (push) Successful in 48s
Build custom container images / build (map[base_image:python:3 build_args:PYTHON_VERSION=3
context:python-tools fingerprint_command:{ dpkg-query -W -f='${binary:Package}=${Version}\n' | LC_ALL=C sort; pip freeze | LC_ALL=C sort; }
name:python-tools oci_labels:org.opencontainers.ima… (push) Failing after 1m48s
Build custom container images / build (map[base_image:python:3.12-slim build_args:PYTHON_VERSION=3.12-slim
context:linkki-tiedotus fingerprint_command:{ dpkg-query -W -f='${binary:Package}=${Version}\n' | LC_ALL=C sort; pip freeze | LC_ALL=C sort; }
name:linkki-tiedotus oci_labels:… (push) Successful in 26s
Build custom container images / build (map[base_image:python:3.12-slim build_args:PYTHON_VERSION=3.12-slim
context:timepoll fingerprint_command:{ dpkg-query -W -f='${binary:Package}=${Version}\n' | LC_ALL=C sort; pip freeze | LC_ALL=C sort; }
name:timepoll oci_labels:org.opencontai… (push) Successful in 34s
This commit is contained in:
1 parent
8a73c13b12
commit
e54f56d910
2 files changed
+65
-8
No files matched your search
@@ -1,3 +1,7 @@
|
||||
import html
|
||||
|
||||
import pytest
|
||||
|
||||
from linkki_poster.formatting import (
|
||||
CAPTION_LIMIT,
|
||||
estimate_caption_length,
|
||||
@@ -123,3 +127,42 @@ def test_apostrophes_are_not_escaped_in_headings_or_plain_text() -> None:
|
||||
assert "'" not in heading
|
||||
assert "'" not in plain_heading_char
|
||||
assert "'" not in bold
|
||||
|
||||
|
||||
|
||||
@pytest.mark.parametrize("url", [
|
||||
"https://example.org/ril_gaala",
|
||||
"https://example.org/a__b++c~~d||e*f",
|
||||
"https://example.org/event?name=ril_gaala&language=fi",
|
||||
])
|
||||
def test_url_labels_and_destinations_are_not_parsed_as_styles(url: str) -> None:
|
||||
rendered = render_template(parse_markdown_template(f"[{url}]({url})"), {})
|
||||
assert rendered == f'<a href="{html.escape(url, quote=True)}">{html.escape(url, quote=False)}</a>'
|
||||
|
||||
|
||||
def test_url_label_remains_literal_when_destination_differs() -> None:
|
||||
rendered = render_template(parse_markdown_template(
|
||||
"[https://example.org/a_b_c](https://example.org/register)",
|
||||
), {})
|
||||
assert rendered == '<a href="https://example.org/register">https://example.org/a_b_c</a>'
|
||||
|
||||
|
||||
def test_formatted_link_label_and_surrounding_styles_still_work() -> None:
|
||||
rendered = render_template(parse_markdown_template(
|
||||
"_Read [**bold** ++underlined++](https://example.org/a_b_c) now_",
|
||||
), {})
|
||||
assert rendered == '<i>Read <a href="https://example.org/a_b_c"><b>bold</b> <u>underlined</u></a> now</i>'
|
||||
|
||||
|
||||
def test_url_underscore_does_not_consume_later_italic_marker() -> None:
|
||||
rendered = render_template(parse_markdown_template(
|
||||
"[Register](https://example.org/ril_gaala) and _italic_",
|
||||
), {})
|
||||
assert rendered == '<a href="https://example.org/ril_gaala">Register</a> and <i>italic</i>'
|
||||
|
||||
|
||||
def test_escaped_link_markers_are_restored_inside_protected_links() -> None:
|
||||
rendered = render_template(parse_markdown_template(
|
||||
r"[https://example.org/ril\_gaala](https://example.org/ril\_gaala)",
|
||||
), {})
|
||||
assert rendered == '<a href="https://example.org/ril_gaala">https://example.org/ril_gaala</a>'
|
||||
Reference in new issue
Block a user