New Comment Features: Turing Test, Live Preview

Saturday, 2006-07-01; 03:52:00

Since I've been getting some comment spam lately -- nothing serious, and I can definitely deal with it by manually deleting it -- I'm gonna see if implementing a Turing test via the commenting system will stop spambots. I'm not going to do any rigorous testing and data collecting to see if it actually stops comment spam, but I'll be able to tell.

Basically how it works is this: if you have JavaScript turned off, the form doesn't show up at all, and if JavaScript is turned on, it requires you to correctly answer the spam test. Conceivably, a spambot could get the HTML, scrape it, get the input fields and the form submission method, and submit comments directly to the enetation server. Since this is a client-side solution and not a server-side solution, enetation would be happy to post spam comments like that. I'm not sure if spambots already do this or not, but I should be able to find out within the next few weeks/months.

So, yeah, the only change is that now you have to fill in the spam test field. In case you're unbelievably out of it, the answer is "e" (or, if you'd like, "E"). I wonder if I could automatically input that into the text field using JavaScript and still outwit bots and make it easier for humans to comment.

The other cool feature I've added (again, JavaScript required) is live comment previews. Since enetation is unbelievably weird in how it parses comments (e.g.: HTML tags <i>, <b>, and < a > work when using either angle or square brackets, but tags like [blockquote], [pre], [code], and [u] must use square brackets), a preview would be nice. I've been able to "preview" my own comments when logged in as admin by just submitting them, and editing them if they didn't look right. Obviously, no one else could do that.

Now no more. Live preview has been launched! The preview box tries to be as faithful to enetation's stylizing as possible, but it's likely that it's not completely respected. It does this by dynamically replacing square bracketed tags into their angle bracket counterparts and then displaying the HTML in the live preview box. Also, regular newline characters created by the return key are automatically translated to <br> tags, since that's what enetation effectively does. Hopefully I've got it close enough so that the live preview is useful.

Props to Scriptygoddess for how to do this, even though the post is almost 4 years old.

(I authorize you to use the comments on this entry only to test out various comments and make sure the preview matches up with what enetation posts, if you want. Let me know of any problems.)

I've already found one problem, though: after using a square-bracketed [a] tag, any subsequent square-bracketed tag will mess up the live preview display. This is because my regular expression match for the square-bracketed [a] tag isn't good enough. The regex is /\[a(.*)\]/<a$1>/g . The problem exhibits itself because the first part of the regex doesn't specifically omit the closing square bracket character ]. That means that this regex seems to match larger expressions first, so it catches the opening "[a" and the ending ] of a different square-bracketed tag. Could someone formulate a regular expression that would match this:

[a href=""]

but not this?:

[a href=""] oogity boogity [/a] [blockquote]

That is, don't allow any closing square brackets ] between the initial opening bracket [ and the final closing bracket ].

Gah, I hate regular expressions.

(You know, honestly, I'm continually surprised at how many normal weblog features I'm able to replicate here even though .mac doesn't support server-side scripting technologies and enetation is kind of annoying.)

Technological Supernova   Tips   Older   Newer   Post a Comment