Incorrect attachment markup generation with underscores in the file name

Found a small bug when uploading file:

If the file starts and ends with underscore (_test_file_.txt in this case), the markup generation code does not escape the underscore, resulting in the following “file name”:
test_file.txt|attachment (23 Bytes)

[_test_file_.txt|attachment](upload://eSJGButIpkpu4IEifmmispiFRJu.txt) (23 Bytes)

If I escape the first underscore with a backslash, it’s parsed correctly:

_test_file_.txt (23 Bytes)

[\_test_file_.txt|attachment](upload://eSJGButIpkpu4IEifmmispiFRJu.txt) (23 Bytes)