Rich text editor converts bbcode into display math

Description

When pasting bbcode into rich text editor, brackets are escaped as \[ and \]. However, this makes it a valid display math block, so it is erroneously rendered as math.

Reproduction

  1. Copy the following text

    [details="summary"]
    some text
    [/details]
    
  2. Paste into something like notepad.exe

  3. Copy from notepad.exe to remove formatting information

  4. Paste into rich text editor

  5. The text should display as code; uncheck the “code” toggle button to make it plain text

Alternatively, you can type the bbcode shown above manually into the rich text editor.

Expected behaviour

Either

summary

some text

which is fine, since that is the original meaning of the bbcode, or

[details=“summary”]
some text
[/details]

which is also fine, since that is what you see in the wysiwyg editor.

Actual behaviour

details="summary"

some text

/details

which is not fine.