wtfutil / wtf

The personal information dashboard for your terminal
http://wtfutil.com
Mozilla Public License 2.0
15.85k stars 803 forks source link

textfile module sometimes removes text in [brackets] #1263

Closed 229c9cf0 closed 2 years ago

229c9cf0 commented 2 years ago

What's broken?

When the displayed text file is e.g. a Markdown-formatted list of recent changes with [[wiki-style]] links, if the link is a single word, like [[projects]], the actual text shown by wtfutil's textfile module is []. (The text following after will be the default text color, so I suspect something is trying to interpret the text as a color/formatting instruction instead of passing it through as text?)

The state of the format config flag doesn't matter, it happens in both cases.

The text / Markdown file that I'm displaying is not under my control and considered untrusted. That means I cannot adjust the text to e.g. add escape sequences to work around this bracket-eating behavior. It also means that strangers are supplying the stuff in the brackets. (How much should that worry me? Is changing the text color all that can happen, or is this mechanism more powerful?)

Expected behavior

By default, text file contents should be displayed as-is (potentially highlighted if format is on), and not interpreted as instructions of any kind.

(If preserving the current behavior is desirable (could be cool to allow external tools to basically behave like a widget), there could be an option to explicitly enable treating the text as an internal data stream containing formatting instructions. This should not be enabled by default.)

Seanstoppable commented 2 years ago

Yeah, this is because text rendering uses brackets to do color codes. From the docs: In the rare event that you want to display a string such as "[red]" or "[#00ff1a]" without applying its effect, you need to put an opening square bracket before the closing square bracket. Note that the text inside the brackets will be matched less strictly than region or colors tags. I.e. any character that may be used in color or region tags will be recognized. It goes on to mention an Escape function that we can leverage.