OngoingWorlds blog

News & articles about play-by-post games, for roleplayers & writers

By

The "one-long-paragraph" problem

Long Paragraph

The post all shows in one long paragraph

split into paragraphs

How the post should look, split into paragraphs

I’ve just fixed a problem which has plagued OngoingWorlds for a week or two (actually, that’s a total overreaction – it has always been a problem but was never noticed until last week!). Mike brought this to my attention last week, just after I’d mentioned that you should always write your post into a separate text editor and paste it into the form on the “Post” page when finished, something happened which completely contradicted me.

Mike rewrote the infamous post which he lost the first time (apparently this rewrite is almost as awesome but not quite) in notepad, and copied the text into the form on the Post page. It all looked great, so he pressed “Post”. Viewing the post afterwards however showed the post slightly different, without any sort of spacing between paragraphs.

The Solution

I’ve had a look at the problem which seems to be this; when displaying the text on the page I use a function to strip out any malicious code, so that hackers can’t put weird code which will make the page display differently. I realised that this function is actually working a bit too strictly, it’s stripping out
tags, which act as linebreaks in the text.

So now, the code I use when outputting all text to the screen is this:

//--trims whitespace
$text = trim($text);
//--strips out any unknown formatting code
$text = strip_tags($text,'<p><a><h1><h2><h3><strong><em><span><ol><ul><li><br>');

Why this problem hadn’t been discovered before

When I created this part of the site I’d tested the Post form by submitting test information, a few lines of characters created by just mashing the keys on my keyboard (like this: asdsaffsfasdafddsf), but not actually writing long sentences and copying them into the textbox.

This problem didn’t take too long to investigate and fix, so you might be wondering why I’m even writing a blog article about it. But this is still only the second bug I’ve found which wasn’t anticipated, which shows to me how important user testing was.

The reason why I haven’t launched this site yet (even in public beta – we’re still in the Alpha/development version) is for exactly this reason, it’s still full of pretty obvious bugs and needs a lot of testing and fixing before I can even say I’m happy enough to launch the Beta version.