# This chat, apparently, is a gigantic coding horror

This topic is 1238 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Yea when me+bact first discovered them(which was a complete accident, as bact was showing some code iirc, and it had ,A, in it) anyway me+him surmised it's some type custom encoding scheme, rather than using base64.

Also if you went through the source code did you try out the bad words?

##### Share on other sites

Also if you went through the source code did you try out the bad words?

I did not go through the source code, but I'm pretty positive this is what's going on. I know there are other quirks, but what do you mean by "trying out the bad words"?

##### Share on other sites
ipb.chat.badwords.set( 'yeahmobi', [ 1, "[A REALLY ANNOYING AND DISREPUTABLE COMPANY THAT SPAMS FORUMS]" ] );
ipb.chat.badwords.set( 'YeahMobi', [ 1, "[A REALLY ANNOYING AND DISREPUTABLE COMPANY THAT SPAMS FORUMS]" ] );

these however do not actually do anything when you type it into chat unfortuantly=-(

edit: also when i was reading the title, i expected code snippets of people in chat, not the chat itself =-P Edited by slicer4ever

##### Share on other sites
What, you mean like this thing that happened yesterday?

Stormynature+> L. Spiro I would never think of you as a whiner...just a very deep navel gazer confused by the mysteries of belly button lint
L. Spiro+> I did do some naval grazing back in my time.
riuthamus has entered the room
riuthamus> naval gazing....
riuthamus> now that i do, im not sure i wanted to...
NightCreature83+> so you go navel gazing instead?
fastcall22> suddenly, i have a strong feeling to clean my navel
fastcall22> my naval ship, that is
fastcall22> all aboard the u.s.s. yourmom, now taking off to the issofat island
riuthamus kicked fastcall22

EDIT:
Or do you mean like anything WiredCat posts? His code gives me nightmares... Edited by fastcall22

##### Share on other sites
ah, that was a classic one fast =-P

##### Share on other sites

Yes, I actually found the code that caused that issue. It comes from some "dirtyMessage" and "undirtyMessage" functions (can't check the exact names now, try and grep the JS code for "dirty") in the javascript code that do exactly what you are saying: replacing special symbols by encoded values to send them over the network. But the encoding and decoding functions are not inverses of each other, and in some circumstances the encoding is ambiguous, which causes the decoding function to decode the wrong thing, resulting in the bug observed. Basically, whoever implemented it tried to be smart, and failed.

Should've just used base64.

Edited by Bacterius

##### Share on other sites

It's especially funny since javascript already has a built in function called encodeURIComponent which replaces certain characters with their respective safe counterparts.

##### Share on other sites

Yeah that was my first thought, but I'm not sure if some symbols aren't still parsed after the decoding (can somebody who knows better confirm if this is the case or not?).

Also why + gets encoded to __PS__ and not __P__? *OCD mode kicks in*

##### Share on other sites

Okay, now that I've checked it's not "dirty" but "clean", close enough.. behold the cleanMessage() function:

function (message) {
message=message.replace(/\r/g,'');
message=message.replace(/\n/g,"__N__");
message=message.replace(/,/g,"__C__");
message=message.replace(/=/g,"__E__");
message=message.replace(/\+/g,"__PS__");
message=message.replace(/&/g,"__A__");
message=message.replace(/%/g,"__P__");
return message;
}


And the unCleanMessage() function:

function (message) {
message=message.replace(/__PS__/g,"+");
message=message.replace(/__P__/g,"%");
message=message.replace(/__A__/g,"&");
message=message.replace(/__E__/g,"=");
message=message.replace(/__C__/g,",");
message=message.replace(/__N__/g,"<br />");
return message;
}


Now take a look at what happens if you type in "=A=" for instance.. the two equal signs get replaced and so it gets encoded to "__E__A__E__". Which then promptly gets decoded to "__E&E__" as the middle part "__A__" happens to get replaced first. Oops

##### Share on other sites

PSycho Phil And Elvis Clean Noodles.
PS P A E C N
+ % & = , \n

##### Share on other sites

OK that explains why it's PS and not P.

Also random thought, but why not just use escape characters like programming languages do? So e.g. instead of = you have \e, instead of & you have \a, etc. (and the escape character itself is escaped, i.e. \\). Replace \ with whatever character would be more suitable.

OK, it still isn't nice but would work with the naive method of replacing and also would reduce bandwidth as a bonus =P (there's risk of invalid escape sequences, but at worst they just will stay unencoded as-is)

##### Share on other sites

well, I hope you're happy with yourself, the chat no longer works :(

##### Share on other sites

yeah gimme my chat back

##### Share on other sites

Posted a message to staff - so hopefully the right people will get the message eventually (Of course USA is asleep atm ) - till then I can only suggest playing the many entries done in the just-past Week of Awesome and post feedback to the various folks who made the games. Either that or do your homework .

edit Meh: why is this in coding horrors.....DSM,,,start a thread in the right forum next time (instead of piggybacking)!

Edited by Stormynature

##### Share on other sites

The crucial bug in this brainfart of a code is not encoding "_" and not the order (it would still be broken regardless of order - the order does not matter, it just makes it worse).

Yep, deserved entry in coding horrors (our own daily wtf of sorts).

##### Share on other sites

so it was you stormy and i was starting to blame fastcall, show me ur ass.

##### Share on other sites

so it was you stormy and i was starting to blame fastcall, show me ur ass.

This thread just took an interesting turn...

##### Share on other sites

so it was you stormy and i was starting to blame fastcall, show me ur ass.

Guilty as charged. This is my ass in jail....again. Damn I might be headed into habitual :(

Edited by Stormynature

##### Share on other sites

I didn't do anything :( OP broke the chat by posting this :( but it works now so is all cool :cool:

##### Share on other sites

Whilst we are taking credit for other peoples work:

if you type (don't copy): &?#x200B , into the chat, you are able to print a blank line (which is not possible by any other means) works quite nicely if you are speechless

##### Share on other sites
No, dsm, that's wrong. It's "&?#x200B;", which is a ZERO WIDTH SPACE, which I've been trying to explain to you this past half hour that it can be used to escape chars:

"__&?#x200B;A__" is displayed as "__A__", whereas
"__A__" is displayed as "&". Edited by fastcall22

##### Share on other sites

No, dsm, that's wrong. It's "&?#x200B;", which is a ZERO WIDTH SPACE, which I've been trying to explain to you this past half hour that it can be used to escape chars:

"__&?#x200B;A__" is displayed as "__A__", whereas
"__A__" is displayed as "&".

I am not wrong. If you trype "&?#x200B" into the chat, you are indeed able to print a blank line.

Now, I wouldn't mind you saying mean things ( :( ) if I was indeed incorrect, but I do believe I never gave an explanation of why it printed a blank line - Which you are unable to do if you press space.

thank you for the information, it is very wise.

P.S.

you 'trying to explain something' constisted of about 2-3 lines of cryptic information

##### Share on other sites
Okay, dsm, I'm sorry for flying off the handle. I just got frustrated because you weren't understanding Unicode and/or HTML.
Anyways, it's not technically a blank line in much the same way " " isn't blank line. The difference is that the latter isn't allowed because it's recognized as just spaces, whereas the former is allowed, because it doesn't recgonize &?#x200B; as a non-printable character.

##### Share on other sites

Okay, dsm, I'm sorry for flying off the handle. I just got frustrated because you weren't understanding Unicode and/or HTML.
Anyways, it's not technically a blank line in much the same way " " isn't blank line. The difference is that the latter isn't allowed because it's recognized as just spaces, whereas the former is allowed, because it doesn't recgonize &?#x200B; as a non-printable character.

me too :wub:

my point was that you can not send the chat message " ". but with 200b you can.

Also, I didn't know you where using uni code, you just saying things :s lol