Code posting woes October 30, 2006 9:05 PM   Subscribe

Just when I thought I'd figured out how to post code into AskMeFi ... some feature of the back end is changing two single quotes into one single quote?
posted by AmbroseChapel to Bugs at 9:05 PM (30 comments total)

This is what you have to do already in order to get code to post:
  1. replace all < characters with &lt;
  2. replace all linebreaks with <br>
  3. optionally, make your indentation work with &nbsp;s instead of leading tabs/spaces
  4. don't preview!
But now it appears I can't even post two single quotes next to each other? Why not? I should escape single quotes with 39; now?
posted by AmbroseChapel at 9:10 PM on October 30, 2006


Aren't single quotes used as string delimiters in a database record?
posted by Blazecock Pileon at 9:10 PM on October 30, 2006


Irony. I can't even post & #39;!
posted by AmbroseChapel at 9:11 PM on October 30, 2006


>Aren't single quotes used as string delimiters in a database record?

Well, first of all, no, and second of all, your point being what? No single quote should be allowed at all? Clearly they are, but not two in a row. Or not two in a row inside the <pre> tag, or something.
posted by AmbroseChapel at 9:13 PM on October 30, 2006


You could just post a link to a txt file on your server.
posted by mathowie (staff) at 9:34 PM on October 30, 2006


Seriously, that's your reply? We should all just give up trying to post code? If so, fair enough, but you should add it to the FAQ.
posted by AmbroseChapel at 9:58 PM on October 30, 2006


use pastie or one of the many other code snippets sites. pastie also does nice line wrapping and code coloring. Big bold snippets is a bit more of a "professional" site for this kinda thing, if you are worried about the snippets being available for evah.
posted by rsanheim at 11:32 PM on October 30, 2006


Maybe I'm missing something, rsanhelm, but what difference does it make if I use a site which wraps lines and colours keywords? If I post two single quotes and then submit them to the MeFi back end, it will fuck them up -- for reasons I can't even guess at.

OK does &apos; work?
if(x == ''){return}
posted by AmbroseChapel at 12:46 AM on October 31, 2006


OK the revised version is now:
  1. replace all < characters with &lt;
  2. replace all linebreaks with <br>
  3. replace all single quotes with &apos;
  4. optionally, make your indentation work with leading &nbsp;s instead of leading tabs/spaces
  5. don't preview!
Should that go in the FAQ? Seriously? And maybe someone can implement it with Greasemonkey or something?
posted by AmbroseChapel at 12:50 AM on October 31, 2006 [1 favorite]


You could just post a link to a txt file on your server.

I think that translates to: "fuck off, not my problem."
posted by bob sarabia at 3:27 AM on October 31, 2006


I've been doing the following to post code:

1. Replace all & with &amp;
2. Replace all < with &lt;
3. Replace all spaces with &nbsp;
4. Surround the whole mess with <code> </code>
5. Preview to make sure all looks OK
6. Click the browser's Back button
7. Post.

Let me check if that still works:

#include <stdio.h>

int main (int argc, char *argv[]) {
    printf ("Two single quotes ' and hello, world\n");
    return 0;
}

posted by flabdablet at 5:46 AM on October 31, 2006 [1 favorite]


The two single quotes showed up OK in preview, and were still there when I clicked Back, but disappeared on posting. So I guess I'll be replacing ' with &apos; from now on as well.
posted by flabdablet at 5:48 AM on October 31, 2006



#include <stdio.h>

int main (int argc, char *argv[]) {
    printf ("Two single quotes '' and hello, world\n");
    return 0;
}

posted by flabdablet at 5:50 AM on October 31, 2006


Cool.
posted by flabdablet at 5:50 AM on October 31, 2006


There's no reason to replace spaces with &nbsp; if you use <PRE>.
posted by Rhomboid at 6:00 AM on October 31, 2006


Ambrose: No, the point was that there are specific services meant to deal with the annoyances of copying and pasting code. Most forums and message boards, such as metafilter, aren't good at it. So its common practice to use pastie or something similiar and just post a link.
posted by rsanheim at 6:04 AM on October 31, 2006


Well, first of all, no, and second of all, your point being what?

My point is that each post probably has to work itself into a database. I was asking a rhetorical question, in that single quotes are often used as delimiters in INSERT queries, and that code for handling SQL injection may strip delimiter characters as a general security precaution. The &apos; entity seems to get around this issue and you may wish to use it.
posted by Blazecock Pileon at 6:14 AM on October 31, 2006


There appears to be no reason to replace line breaks with <BR> if you use <CODE>.
posted by flabdablet at 6:43 AM on October 31, 2006


Better solution:

1) Post it to a nopaste site.
2) Link to the code there.
posted by Plutor at 9:22 AM on October 31, 2006


Better solution:

1) Post it to a nopaste site.
2) Link to the code there.
posted by Plutor at 9:23 AM on October 31, 2006


Oh, peanuts.
posted by Plutor at 9:23 AM on October 31, 2006


metafilter: you could just post a link to a txt file on your server.
posted by quonsar at 11:02 AM on October 31, 2006


Blazecock Oh, I get it now. Rather than posting code to Ask, or posting a link to a text file, we should post a link to a third-party site. That's ... not a solution really, is it? Why the hell shouldn't I be able to post code here?

>I think that translates to: "fuck off, not my problem."

Well exactly.

I guess what really annoys me, and I'm getting ready for a traditional pile-on of hatred even as I type this, is the weeks of work that were spent on AJAX wank when this site can't even get the basics right.

I have a picture of MeFi as a building. Matt's up on the roof, building a spire next to a minaret next to a cupola, but meanwhile downstairs, none of the toilets flush.
posted by AmbroseChapel at 12:42 PM on October 31, 2006


perfect.
posted by quonsar at 12:47 PM on October 31, 2006


Why the hell shouldn't I be able to post code here?

But you are able to post code. You just have to know a little HTML, which has been explained to you. Is it really that difficult?
posted by Blazecock Pileon at 1:33 PM on October 31, 2006


Yes, Blazecock, it is, which is the whole point of this thread.
posted by Khalad at 1:35 PM on October 31, 2006


>You just have to know a little HTML, which has been explained to you. Is it really that difficult?

Yes, it is that difficult, and I know more than a little HTML, and, you don't seem to know who's posting what. I'm one of the ones doing the explaining.

This thing about single quotes is particularly baffling, because it only happens when there are two of them, it didn't use to happen, and I can't even think of a logical explanation for it.

Thanks Khalad.
posted by AmbroseChapel at 3:45 PM on October 31, 2006


whatever you do, don't flush.
posted by quonsar at 4:40 PM on October 31, 2006


If it's yellow, let it mellow.
posted by Kwine at 6:36 PM on October 31, 2006


Ech, you can flush a cupola times, but not too much.
posted by koeselitz at 6:58 PM on October 31, 2006


« Older What's up with Killroy?   |   how about mefi personals? Newer »

You are not logged in, either login or create an account to post comments