What version of bat are you using?
bat 0.15.4
Describe the bug you encountered:
Some values for --file-name cause escape characters in the input to be printed in the output instead of parsed by the shell. For instance, here with t.s:
โ bat --file-name="t.s" test.txt
โโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ File: t.s
โโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
1 โ [0m[34mHello, world![0m[00m
โโโโโโโโดโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
The test file test.txt was created like this:
โ echo "${fg[blue]}Hello, world\!$reset_color" > test.txt
Note: While I use zsh here, the same problem manifests in bash.
Bizarrely, very similar patterns like t.a work fine:
โ bat --file-name="t.a" test.txt
โโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ File: t.a
โโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
1 โ Hello, world!
โโโโโโโโดโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
While other similar patterns like t.t cause random colors to appear:

Describe what you expected to happen?
โ echo "${fg[blue]}Hello, world\!$reset_color" | bat --file-name="t.t"
โโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ File: t.t
โโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
1 โ Hello, world!
โโโโโโโโดโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ echo "${fg[blue]}Hello, world\!$reset_color" > test.txt && bat --file-name="t.t" test.txt
โโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ File: t.t
โโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
1 โ Hello, world!
โโโโโโโโดโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
How did you install bat?
brew install bat
system
------
**$ uname -srm**
Linux 5.4.0-40-generic x86_64
**$ lsb_release -a**
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 20.04 LTS
Release: 20.04
Codename: focal
bat
---
**$ bat --version**
bat 0.15.4
**$ env**
PAGER=less
bat_config
----------
bat_wrapper
-----------
No wrapper script for 'bat'.
bat_wrapper_function
--------------------
No wrapper function for 'bat'.
No wrapper function for 'cat'.
tool
----
**$ less --version**
less 551 (GNU regular expressions)
@eth-p I guess this is related to recent changes where we made the --file-name argument a possible source for selecting the correct syntax, right? Did we make the right choice in light of the example here?
@MTCoster If you try to use bat to display files with ANSI escape sequences, you are very likely to experience garbage output (unless you use --plain or --show-all) because bat is going to add some ANSI escape sequences on top of the existing ones (if it tries to syntax highlight the input). To avoid strange behavior when choosing a --file-name, try to fix the language with --language. For plain text, use --language txt.
@eth-p I guess this is related to recent changes where we made the
--file-nameargument a possible source for selecting the correct syntax, right? Did we make the right choice in light of the example here?
I think we did. By using the --file-name argument as part of the syntax detection, we made bat more consistent in its behavior. It also came as a huge benefit to scripts, so that they don't need to write to intermediate files or maintain their own list of known extension to syntax mappings.
This issue is one of the more obscure cases where using the file name for syntax detection is undesirable. I can't think of any scenario where I would intentionally provide an incorrect file extension for syntax highlighting, though.
@MTCoster, is this issue something you come across regularly? If you could provide a little bit of detail on the workflow that lead to you discovering this unintended behavior, it would help us figure out what steps that can be taken to solve the problem without introducing any breaking changes.