Skip to content
This repository was archived by the owner on Aug 14, 2023. It is now read-only.

Remove file extensions from locked URLs for hastebin#121

Merged
jb3 merged 4 commits into
mainfrom
monkey-patch-url-extensions-hastebin
Feb 17, 2022
Merged

Remove file extensions from locked URLs for hastebin#121
jb3 merged 4 commits into
mainfrom
monkey-patch-url-extensions-hastebin

Conversation

@lemonsaurus
Copy link
Copy Markdown
Contributor

@lemonsaurus lemonsaurus commented Feb 17, 2022

Recently, Discord has implemented a suspicious file scanning feature which marks any URL with a .py in it as a suspicious URL.

This means, users who use our paste.pythondiscord.com service will be met with this lovely screen:

image

This hideous monster of a monkey patch will comment out the line of code that adds the file extension to the URL, thereby ensuring that you will just get a flat URL when you save. E.g., instead of paste.pythondiscord.com/omaimadnaoida.py, you'll just get paste.pythondiscord.com/omaimadnaoida when you hit save.

I've made this monkeypatch fail hard if it fails, so if the code changes and this approach is no longer viable, it should break the entire build, thereby alerting us that we need to change (or remove) the monkey patch to build this service. That seems better than silently failing to remove the .py and reintroducing the bug.

How does this work?

It just comments out a single line in haste-server, which is responsible for adding this extension to the URL before it gets pushed to your history. The specific line and the context can be found here:
https://github.com/toptal/haste-server/blob/master/static/application.js#L249

Why a monkey patch?

Because forking haste-server means maintaining the fork. This will theoretically keep working until this particular line is changed, and honestly it would be weird if that ever happened, this line is very simple and I can't imagine why they would change it at all.

It's likely that this will work for the foreseeable future, and without forcing us to maintain a fork, and without missing out on future updates. We can keep using the latest version of this tool, and if it breaks, we'll just adjust the monkeypatch or get rid of it. It's not a big deal, it'll just fail to deploy. Users won't even notice.

@lemonsaurus lemonsaurus requested a review from a team as a code owner February 17, 2022 20:34
@lemonsaurus
Copy link
Copy Markdown
Contributor Author

PR tested, and is currently live on https://paste.pythondiscord.com.

Works as intended now.

Copy link
Copy Markdown
Member

@jb3 jb3 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lemon, excellent work my friend. Great stuff! :shipit:

@jb3 jb3 merged commit c1f5337 into main Feb 17, 2022
@jb3 jb3 deleted the monkey-patch-url-extensions-hastebin branch February 17, 2022 21:13
Copy link
Copy Markdown
Contributor

@jchristgit jchristgit left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants