Repository: aiogram/aiogram
Pull request #1176 (2023-05-10 22:52:08)

Fix markdown spoiler
# Description
In [telegram bot api documentation](https://core.telegram.org/bots/api#markdownv2-style) said that need two characters, but there we have only one. I did catch a bug with this, but github issue I didn't find and don't want to create.

## Type of change

- Bug fix (non-breaking change which fixes an issue)

# How Has This Been Tested?

I tested it on my own project, but you can use this code:
```python
...
@router.message()
async def test(m: types.Message):
    return await m.answer(m.md_text)
```

github-actions[bot]: # :x: Changelog is required!

You need to add a brief description of the changes to the `CHANGES` directory.

For example, you can run `towncrier create <issue>.<type>` to create a file in the change directory and then write a description on that file.

Read more at [Towncrier docs](https://towncrier.readthedocs.io/en/latest/quickstart.html#creating-news-fragments)
JrooTJunior: Wow, It's huge work, cool

I've been thinking about writing my own asgi for webhook before, this is a promising optimization direction and you confirmed my theories, thanks.

I'n not totally understand why you change pydantic to another library, such kind of changes cannot be performed at the current stage of development, it is planned to publish last beta, then few pre-releases (code-freeze, only bug-fixes and small changes can be applied) and then grand release of 3.0.

Also i have plans to change pydantic to dataclasses for 4.0 version, because it is really slow in some cases and provides too many possibilities instead of having simple serialization to solve the current problem. I like pydantic, but not for all tasks, really.

Another point that you have changed all models, but it shouldn't touched manually, it should be changed in Butcher templates (our docs parser and code-generation platform), because i don't want to support new Bot API features manually, i have implemented Butcher instead.

Also as can i see you change multipart/form-data response to application/json, but this is unacceptable in due to files can't be sended to Telegram via JSON response, you can upload file from response only via multipart/form-data.

Conclusion: i can't apply this pull-request, but i'd like to have own asgi server, if you can rework this pull-request without changing pydantic and change JSON to multipart/form-data response and add possibility to use multiple Bot instances on the server please do it. If you can't do it, i can do it by myself after grand release.

JrooTJunior: ![image](https://github.com/aiogram/aiogram/assets/6726423/69ca9af0-f834-4a77-b37e-c3c79be2db57)

> ... and update tests

I see that tests still not updated

Just look at test results: https://github.com/aiogram/aiogram/actions/runs/4951994811/jobs/8858509304?pr=1176
codecov[bot]: ## [Codecov](https://app.codecov.io/gh/aiogram/aiogram/pull/1176?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=aiogram) Report
> Merging [#1176](https://app.codecov.io/gh/aiogram/aiogram/pull/1176?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=aiogram) (c8dd635) into [dev-3.x](https://app.codecov.io/gh/aiogram/aiogram/commit/cf269e15f4a098b051f97bc68bb2e710d3d61d8a?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=aiogram) (cf269e1) will **not change** coverage.
> The diff coverage is `100.00%`.

[![Impacted file tree graph](https://app.codecov.io/gh/aiogram/aiogram/pull/1176/graphs/tree.svg?width=650&height=150&src=pr&token=cFqEr3p9MX&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=aiogram)](https://app.codecov.io/gh/aiogram/aiogram/pull/1176?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=aiogram)

```diff
@@            Coverage Diff            @@
##           dev-3.x     #1176   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files          358       358           
  Lines         8841      8841           
=========================================
  Hits          8841      8841           
```

| Flag | Coverage Δ | |
|---|---|---|
| unittests | `100.00% <100.00%> (ø)` | |

Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=aiogram#carryforward-flags-in-the-pull-request-comment) to find out more.

| [Impacted Files](https://app.codecov.io/gh/aiogram/aiogram/pull/1176?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=aiogram) | Coverage Δ | |
|---|---|---|
| [aiogram/utils/text\_decorations.py](https://app.codecov.io/gh/aiogram/aiogram/pull/1176?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=aiogram#diff-YWlvZ3JhbS91dGlscy90ZXh0X2RlY29yYXRpb25zLnB5) | `100.00% <100.00%> (ø)` | |


Patch:
diff --git a/CHANGES/1176.bugfix.rst b/CHANGES/1176.bugfix.rst
new file mode 100644
index 00000000..57f67202
--- /dev/null
+++ b/CHANGES/1176.bugfix.rst
@@ -0,0 +1,1 @@
+Fixed the markdown spoiler parser.
diff --git a/aiogram/utils/text_decorations.py b/aiogram/utils/text_decorations.py
index 70f96388..97430a32 100644
--- a/aiogram/utils/text_decorations.py
+++ b/aiogram/utils/text_decorations.py
@@ -233,7 +233,7 @@ class MarkdownDecoration(TextDecoration):
         return f"~{value}~"
 
     def spoiler(self, value: str) -> str:
-        return f"|{value}|"
+        return f"||{value}||"
 
     def quote(self, value: str) -> str:
         return re.sub(pattern=self.MARKDOWN_QUOTE_PATTERN, repl=r"\\\1", string=value)


Test patch:
diff --git a/tests/test_utils/test_text_decorations.py b/tests/test_utils/test_text_decorations.py
index 01fbabb6..056bd1cb 100644
--- a/tests/test_utils/test_text_decorations.py
+++ b/tests/test_utils/test_text_decorations.py
@@ -90,7 +90,7 @@ class TestTextDecoration:
             [markdown_decoration, MessageEntity(type="bot_command", offset=0, length=5), "test"],
             [markdown_decoration, MessageEntity(type="email", offset=0, length=5), "test"],
             [markdown_decoration, MessageEntity(type="phone_number", offset=0, length=5), "test"],
-            [markdown_decoration, MessageEntity(type="spoiler", offset=0, length=5), "|test|"],
+            [markdown_decoration, MessageEntity(type="spoiler", offset=0, length=5), "||test||"],
             [
                 markdown_decoration,
                 MessageEntity(type="custom_emoji", offset=0, length=5, custom_emoji_id="42"),