TotallyNotRobots / CloudBot

CloudBot - The simple, fast, expandable, open-source Python IRC Bot!
GNU General Public License v3.0
73 stars 41 forks source link

.git shortening does not work properly #420

Closed Vault108 closed 3 years ago

Vault108 commented 3 years ago

The .git command does not shorten urls properly(how ever converting a short url to the full url works as expected) it results in the following message from the bot:

01:05:51 AM .git https://github.com/xxxxx/xxxxxxx/commit/xxxxxxxxx 01:05:52 AM <%gonzobot> (xxxxxxxxx) [HTTP 200] <!DOCTYPE html> git.io <!--[if (gte IE 6)

Actual url masked for privacy reasons

The console provides the following message:

[01:09:43] [ERROR] Error in hook shorten:gitio
Traceback (most recent call last):
  File "/home/vault108/CloudBot-1/cloudbot/plugin.py", line 530, in internal_launch
    out = await task
  File "/usr/lib/python3.8/concurrent/futures/thread.py", line 57, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/home/vault108/CloudBot-1/cloudbot/plugin.py", line 499, in _execute_hook_threaded
    return call_with_args(hook.function, event)
  File "/home/vault108/CloudBot-1/cloudbot/util/func_utils.py", line 26, in call_with_args
    return func(*args)
  File "/home/vault108/CloudBot-1/plugins/shorten.py", line 80, in gitio
    return web.shorten(url, custom=custom, service="git.io")
  File "/home/vault108/CloudBot-1/cloudbot/util/web.py", line 109, in shorten
    return impl.shorten(url, custom, key)
  File "/home/vault108/CloudBot-1/cloudbot/util/web.py", line 327, in shorten
    raise ServiceHTTPError(r.text, r) 
cloudbot.util.web.ServiceHTTPError: [HTTP 200] <!DOCTYPE html>
<html lang='en'>
  <head>
    <title>git.io</title>
    <meta charset='utf-8' />
    <meta content='IE=edge,chrome=1' http-equiv='X-UA-Compatible' />
    <link href="/stylesheets/site.css" media="screen" rel="stylesheet" type="text/css" />
    <script src="/javascripts/modernizr.js" type="text/javascript"></script>
    <script src="/javascripts/modernizr-tests.js" type="text/javascript"></script>
    <!--[if (gte IE 6)&(lte IE 8)]>
      <script src="/javascripts/selectivizr-min.js" type="text/javascript"></script>
    <![endif]-->
  </head>
  <body>
    <div id='container'>
      <div id='bar'>
        <span id="error" class='arrow_box'>
          Sorry yo. That's an invalid URL.
        </span>
        <div class='side' id='front'>
          <form action="/create" method="post">
            <h1 class="logo"><a href="https://git.io/">Git.io</a></h1>
            <input id="input-url" placeholder="Enter a URL to shorten..." type="text" />
            <button>Shorten</button>
          </form>
        </div>
        <div class='side' id='back'>
          <h1 class="logo"><a href="https://git.io/">Git.io</a></h1>
          <input id="output-url" readonly type="text" />
          <button id="copy-button">Copy</button>
          <span id='copied-msg'>Copied!</span>
          <a id="restart" href="#">Shorten another URL</a>
        </div>
      </div>
      <footer>
        <a href="https://github.com/site/terms">Terms of Service</a>
        <a href="https://github.com/site/privacy">Privacy</a>
        <a href="https://github.com/security">Security</a>
        <a href="https://github.com" class="invertocat">
          <img src="/images/invertocat.png" width="24" height="24" />
        </a>
        &copy; <span id="year">2021</span> GitHub Inc. All rights reserved.
      </footer>
    </div>
  </body>
  <script src="/javascripts/jquery-1.7.1.min.js" type="text/javascript"></script>
  <script src="/javascripts/ZeroClipboard.js" type="text/javascript"></script>
  <script src="/javascripts/jquery.defaultvalue.js" type="text/javascript"></script>
  <script src="/javascripts/site.js" type="text/javascript"></script>
  <script type="text/javascript">
    GitIO.url = "https://git.io";
  </script>
</html>
Vault108 commented 3 years ago

It seems the issue was https://github.com/TotallyNotRobots/CloudBot/blob/14ff80603dfe59b131f0d22a790f223013bf9ea4/cloudbot/util/web.py#L308-L329 It used HTTP where it needed to be HTTPS. Should the others be switched from HTTP's to HTTPS?