26

When trying to fix an error in the code example of an old question for posterity, the editor will not let me save the change because the 'Body cannot contain "http://tinyurl.com/api". The TinyURL string is being used in a code example and it not actually linking to content outside of StackOverflow.

Although I imagine this is a very small corner case, would it be worthwhile to ignore URL shorteners that are in code examples?

My question for reference: Generate TinyURL with client side javascript--need CORS workaround

Screenshot of editor error

6
  • 6
    This would leave the option to abuse codeblocks....you can still get the point across by using a slightly different name "smallurl" and making a suitable comment.
    – Paulie_D
    Aug 26, 2016 at 21:01
  • 7
    Seems reasonable to add an exception for the api to tinyurl, even if the generated urls aren't allowed.
    – davidism
    Aug 26, 2016 at 21:10
  • 2
    It looks the question is about CORS and whether TinyURL supports it. In that case, the actual URL of the API is irrelevant... Aug 26, 2016 at 21:13
  • @yellowantphil They might be aiming higher than "not any worse" ;) Aug 26, 2016 at 21:47
  • Why not replace it with example.com? Aug 27, 2016 at 6:23
  • I agree, I can easily get the point across by using AnyURLShorternerHere.com in the code example, but I also want people to be able to run the code snippet and have it work. I really appreciate all of you making me consider how relevant the API actually is to my question, and now see that allowing URL shorteners in some instances could open the door to abuse.
    – coffeecola
    Aug 29, 2016 at 22:20

2 Answers 2

17

As a workaround you should be able to use a <pre></pre> block instead of the usual 4 space indent and then break up the URL with an HTML comment. Something like:

<pre>
var tinyAPI = 'http://tiny<!---->url.com/api-create.php?url=';
</pre>

Which would end up looking like this:

var tinyAPI = 'http://tinyurl.com/api-create.php?url=';
2
  • Thank you for this workaround. I am accepting this answer (although there was some internal debate about if I should pick Laurel's) because it allows me to edit my question to completely change the code example.
    – coffeecola
    Aug 29, 2016 at 22:06
  • Thanks for this. I wanted to provide a code example specifically involving a URL shortener as part of an answer about HTTP redirects, and this stupid filter prevented me from doing so. Glad that there's a workaround, and hope it doesn't get closed.
    – Mark Amery
    Aug 31, 2016 at 21:59
18

Yes, legitimate cases of link shorteners were something that I ran into quite a lot while I was Removing link shorteners from posts!

Obviously, I never finished that project (there's just too much for me alone, especially once you consider dead links).

I found a few ways to bypass the filter, but it comes at the expense of the clarity of the post. Within code, the best method is to change (for example):

"http://ppcg.ga/1234"

to

"http://" + "ppcg.ga/1234"

Ideally, the questions tagged (and their answers) should be exempt from the ban. (This solution opens up different paths for abuse, of course. But it might be worthwhile to request.)

1
  • No, use of shorterners in code blocks (where they are neutralised) should work, and no exceptions outside of code blocks. Spammers would be very quick to exploit such an opening.
    – Martijn Pieters Mod
    Aug 3, 2018 at 10:26

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .