chubin / chubin/cheat.sh

raw html in terminal when user-agent is set

Open
#407 0 comments 1 reaction 0 assignees View on GitHub
Dominant language
Python
Stars
41.7k
Forks
1.9k
PR merge metrics
No merged PRs in 30d

Description

Bug: When the user-agent is set the output to terminal is raw html.

I ran into this issue because the the user-agent was set in my curlrc.

Suggested fix 1: Use mime type like `text/plain` or `application/text` to detect terminal users.
Suggested fix 2: Use `text/html` mime type to detect browser users and default otherwise to text.

## Reproducible Example

**input**

```bash
curl -H 'user-agent: "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36"' cht.sh/:styles-demo
```

**output (truncated)**

```html

cheat.sh/:styles-demo

.ef0,.f0 { color: #073642; } .eb0,.b0 { background-color: #073642; }
.ef1,.f1 { color: #D30102; } .eb1,.b1 { background-color: #D30102; }
.ef2,.f2 { color: #859900; } .eb2,.b2 { background-color: #859900; }
.ef3,.f3 { color: #B58900; } .eb3,.b3 { background-color: #B58900; }
...
<a href="https://twitter.com/igor_chubin" class="twitter-follow-button" data-show-count="false" data-button="grey">Follow @igor_chubin</a>
<script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0],p=/^http:/.test(d.location)?'http':'https';if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src=p+'://platform.twitter.com/widgets.js';fjs.parentNode.insertBefore(js,fjs);}}(document, 'script', 'twitter-wjs');</script>

<!-- Place this tag where you want the button to render. -->
<a aria-label="Star chubin/wttr.in on GitHub" data-count-aria-label="# stargazers on GitHub" data-count-api="/repos/chubin/cheat.sh#stargazers_count" data-count-href="/chubin/cheat.sh/stargazers" data-icon="octicon-star" href="https://github.com/chubin/cheat.sh" class="github-button">cheat.sh</a>

<!-- Place this tag right after the last button or just before your close body tag. -->
<script async defer id="github-bjs" src="https://buttons.github.io/buttons.js"></script>
</body>
</html>
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.