Problems with symbols disappearing in posts

Started by Snarky, Tue 24/03/2020 14:00:08

Previous topic - Next topic

Snarky

Recently there's been a problem where certain symbols do not appear in posts, but are replaced by spaces. See line 16 in the post here, for example.

Edit: I'm not sure how it's triggered, exactly, since it seems to work OK in this post.

Plus symbols: +
Ampersand symbols: &

(But not in preview, where both symbols fail to render, as well as everything after the ampersand.)

If you quote or edit the post, they remain gone.

Obviously this is very bad when posting code in particular.

In this post it's also suggested that under certain circumstances it can "break" the post, though I'm not sure exactly what's meant by that (maybe the preview problem?).

Khris

#1
The bug should be an easy fix; the problem is that the post content is sent as query string, where the ampersand is used as a separator and the plus sign as space.

This line
Code: javascript

  x[x.length] = textFields[i] + '=' + document.forms.postmodify[textFields[i]].value.replace(/&#/g, '&#');

is I guess supposed to deal with ampersands in the post content but doesn't work at all.

The proper function to deal with characters like that is encodeURIComponent

You can in fact replace ampersands with  %26  and you will see them in the preview, which means the server-side expects URI encoded strings.

AGA

SMF is written to maximise compatibility; it has workaround for super obsolete stuff like IE 4 in it.  Chances are encodeURIComponent wasn't 100% supported at some point so they tried to write their own workaround.

Seems to work okay with that line changed to:

Code: javascript
x[x.length] = textFields[i] + \'=\' + encodeURIComponent(document.forms.postmodify[textFields[i]].value);


I edited the post Snarky linked, and previewed, and it looked okay in both preview and post...

Khris


TheManInBoots

#4
I'm really happy about this improvement! This has been bugging me for a while.
Thanks

TheManInBoots

#5
This does not seem to have been properly debugged.

It happened to me again with ++ symbols.

SMF spam blocked by CleanTalk