ElkArte Community

Elk Development => Bug Reports => Exterminated Bugs => Topic started by: Ruth on April 18, 2016, 05:22:21 am

Title: Preview in PM
Post by: Ruth on April 18, 2016, 05:22:21 am
Not sure, if there is something wrong:

I was sending a PM by using the preview a few times, and as I believe each of the previews was sent as a PM.

I could not send the final PM, because  the limit of 4 PMs per hour was reached.
Title: Re: Preview in PM
Post by: TE on April 18, 2016, 05:25:28 am
Quote from: Ruth – I was sending a PM by using the preview a few times, and as I believe each of the previews was sent as a PM.

I could not send the final PM, because  the limit of 4 PMs per hour was reached.
yep, I was the one who got those PMs.. definitely a bug..  Also: german umlauts are cluttered, not sure if you copied your text from  another software to ElkArte?!?
Title: Re: Preview in PM
Post by: Ruth on April 18, 2016, 05:31:33 am
Quote from: TE – Also: german umlauts are cluttered, not sure if you copied your text from  another software to ElkArte?!?

Yes...there were some quotes from my "broken" SMF-Forum in the PM, TE.  :-[  Sorry.
(Die Umlaute sind da doch teilweise kaputt, die fehlerhafte Anzeige kann auch daher kommen)
Title: Re: Preview in PM
Post by: TE on April 18, 2016, 05:35:20 am
Quote from: Ruth – Yes...there where some quotes from my "broken" SMF-Forum in the PM, TE.  :-[  Sorry.
(Die Umlaute sind da doch teilweise kaputt, die fehlerhafte Anzeige kann auch daher kommen)
No problem, just wanted to make sure this is not another ElkArte related bug.. those broken characters are ISO-8859-1 coded umlauts (and repairable)..
Title: Re: Preview in PM
Post by: emanuele on April 18, 2016, 05:51:25 am
/me whistles innocently
Title: Re: Preview in PM
Post by: Ruth on April 18, 2016, 05:56:02 am
/me would like to send more than 4 PMs a hour


TE, maybe we can talk about the further things about the migration here?

http://support.ElkArte-hilfe.de/index.php/topic,167.0.html

Title: Re: Preview in PM
Post by: Ruth on April 18, 2016, 07:55:03 am
Quote from: TE – just wanted to make sure this is not another ElkArte related bug.

@TE

I did not copy the begin of my PM, just the quotes.

So I think, that ä, ö, ü and ß will get broken in PM, if you use the preview first.



Edit: And if I use the preview in a reply in a topic I will see them broken too:

QuoteSo I think, that ä, ö, ü and ß will get broken in PM, if you use the preview first.


2. Edit:

My account-settings say, that my favorite language is english ;) it has been german before. So maybe the umlaut-mistake is just because all profile settings are now in default?

I cannot change my profile, I have forgotten my password.
Title: Re: Preview in PM
Post by: TE on April 18, 2016, 09:06:15 am
Bug can happen if you click preview more than once..

for reference: öäüß
result after preview: öäüß
Title: Re: Preview in PM öäüß
Post by: emanuele on April 18, 2016, 11:07:59 am
Looks like the strings (body and subject) are not properly encoded before being sent to the server before the preview.
Title: Re: Preview in PM
Post by: emanuele on April 18, 2016, 11:26:47 am
Quote from: Ruth – /me would like to send more than 4 PMs a hour

I didn't know it was set... :-[
But in the meantime I caught a problem with the site, apparently it won't let me change settings in the admin panel, even though locally works fine.
There are few other settings to tweak, but at the moment I can't.
Title: Re: Preview in PM
Post by: emanuele on April 19, 2016, 04:47:08 pm
I fixed the preview in fcf89327935fb0031e291b6c20e8585bf0cdf81a

The problem with the special characters seems to be the result of the "usual" mixed status the AJAX calls are all around the code.
In these AJAX calls (PM previews and posts previews, plus few other places), the texts are converted to 8bit strings before being sent to the server. In 1.0, that string was somehow processed and returned properly to the client, now it is not and the characters result broken.

If I understand correctly the problem, I would be tempted to drop entirely the usage of php_to8bit from the codebase, but TBH it's something I'm a little worried about...
What do you think? Scrap during beta and if something is broken let's find a solution, or let's find a solution to the preview before facing the "real" issue?
Title: Re: Preview in PM
Post by: Spuds on April 19, 2016, 04:54:08 pm
Would you have to update all the xml to json ?  I don't know if  xml is going to handle all of utf8 stuff so I thought that was why the utf8_encode (on the js side via  php_to8bit was done).

Anyway for a 1.1 I don't think we should be redoing that, IMO  All of that was fine in 1.0 ...  I do remember having to update things for some of the 4 byte utf8 items.
Title: Re: Preview in PM
Post by: emanuele on April 19, 2016, 05:49:45 pm
No, this is not the time for a xml => json overhaul!! Not at all! :o

From what I read online (e.g. [here] (http://www.ibm.com/developerworks/library/x-utf8/) or here (http://www.utf-8.com/)), XML has complete support for UTF8.

But, looking at the repo, I see you have removed several php_to8bit:
42cd7e6308e60bd2178191c1501ea0824fa9e13f
d0233a94b95d08b3d25d58f01647a57e412702ba
3f10aed5c6f924df25d29c61580c46657e3d2063
that would be the same, just in the ajax call for previews.
Title: Re: Preview in PM
Post by: Spuds on April 19, 2016, 06:04:00 pm
Well I least I said it may be breaking :P

That update to add encodeURIComponent should have taken care of everything .. hummm
Title: Re: Preview in PM
Post by: emanuele on April 19, 2016, 06:16:49 pm
I guess we can put it live here and see if it breaks anything. O:-)

Done, hard-refresh is mandatory, though I changed the CACHE_STALE to try force it.

ETA: looks good for the moment. :D
Title: Re: Preview in PM
Post by: TE on April 20, 2016, 05:25:12 am
Still getting several PMs with the preview button but the charset problem seems to be fixed  :)
Title: Re: Preview in PM
Post by: emanuele on April 20, 2016, 05:38:56 am
me may have forgot to upload the code. O:-)
Title: Re: Preview in PM
Post by: Frenzie on April 20, 2016, 05:41:53 am
Quote from: Spuds – Would you have to update all the xml to json ?  I don't know if  xml is going to handle all of utf8 stuff
Uh, XML is like the (initial) UTF-8 stronghold, lol. I reckon it's far more likely that some old version of PHP had issues with it. ;)

Edit: I just got nothing (white page) trying to submit this from preview. Could've been that a new reply had been posted while I was typing this.
Title: Re: Preview in PM
Post by: Spuds on April 20, 2016, 09:40:05 am
QuoteUh, XML is like the (initial) UTF-8 stronghold, lol. I reckon it's far more likely that some old version of PHP had issues with it. ;)
Then I look forward to your PR where all that encoding is removed ;)
Title: Re: Preview in PM
Post by: Frenzie on April 20, 2016, 09:57:09 am
I thought @emanuele did that already. :P
Title: Re: Preview in PM
Post by: Spuds on April 20, 2016, 10:08:17 am
Nope ... I had updated the code in 1.1 to use some built in "php to 8 bit" JS functions since we did not have to concern ourselves with older browser support. 

A couple of those calls were missed causing double encoding.  However if we feel that no encoding is required for 1/2/3/4 byte utf8 then cool, but that was not a step I took in my original PR.
Title: Re: Preview in PM
Post by: Frenzie on April 20, 2016, 10:21:52 am
It supposedlly shouldn't be for PHP 5.recent,  but I don't know enough about strings and characters in 5.older to say. It's just not XML that has the issues. ;)

Edit: posting from mobile and finally saw the loading... during quick edit!
Title: Re: Preview in PM
Post by: Spuds on April 20, 2016, 10:32:31 am
Next time I'll be sure to read all the specifications before I ask a question  O:-) XML is the one.
Title: Re: Preview in PM
Post by: emanuele on April 20, 2016, 12:02:35 pm
My original idea (the one that I pushed) was to remove all the calls to php_to8bit from the js, and now I feel it was the way to go since from what I understood, Spuds added this to the urlencode function, and it seems to work! :)
I wouldn't touch for now anything else, just to avoid break something in some odd manner, though in 2.0 it may even be beneficial to consolidate all the AJAX calls passing through jQuery, so that we have to care only about how the jQuery developers decide to change the methods to call. LOL
Title: Re: Preview in PM
Post by: Frenzie on April 20, 2016, 12:12:42 pm
I assume jQuery uses fetch with a fallback?
Title: Re: Preview in PM
Post by: Frenzie on April 21, 2016, 02:29:17 am
Note to self: jQuery.get() doesn't use fetch, probably nor should it.

@Spuds I don't really see any places where php_urlencode should be dropped? I mean, it's applied to URI components after all. And on the PHP side of things all I see is the correct filtering of a couple of disallowed characters:

Code: [Select]
function cleanXml($string)
{
// http://www.w3.org/TR/2000/REC-xml-20001006#NT-Char
return preg_replace('~[\x00-\x08\x0B\x0C\x0E-\x19\x{FFFE}\x{FFFF}]~u', '', $string);
}

Long story short, I set out to perform the cleaning you suggested and all I found was the php_urlencode() function itself.