tel8618217223380 / prado3

Automatically exported from code.google.com/p/prado3
Other
0 stars 0 forks source link

Accented characters cause crashes on TActiveTextBox updates. #475

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Put a TActiveTextBox inside you page.
2. From another active control, update the text inside the TActiveTextBox with 
a text that contains accented characters.
3. The server side crashes.

What is the expected output? What do you see instead?

I expect to see my text with accented characters inside the TActiveTextBox.

What version of the product are you using? On what operating system?

Verified against the latest version (3.2.2) and trunk also. (23 August 2013 - 
15:16)
I use Linux Mint Maya.

Please provide any additional information below.

Note that calling htmlentities on the server side causes a à or ì 
to be shown inside the TActiveTextBox. The only workaround i found is removing 
all accented letters and putting an apos after the letter (caffè -> caffe').

Original issue reported on code.google.com by marco.ba...@gmail.com on 23 Aug 2013 at 1:19

GoogleCodeExporter commented 9 years ago
I've created a simple testcase to test the issue.
There are 2 different things to discuss here:
1) Serverside "crash" when updating in a callback a TActiveTextBox's Text with 
a text that contains accented characters:
This is supposed to work, i suggest you to check your log files to understand 
what is failing. The simple testcase i attached is working flawless in my tests.
2) Updating in a callback an active control with some text containing html 
entities:
Active controls are updated during callbacks using javascript. Unfortunately 
html entities have no "special meaning" in javascript and they are treater as 
raw text (see the 2nd and 4th example in the testcase).
The only way to make them work would be to create a html_entity_decode() clone 
in javascript and use it everytime we update an active control 
(Prado.Element.setValue(), scripaculous-adapter.js:222).
Implementing a base translation matrix (& => &, > => >, ...) can appear like a 
simple solution, but as soon as you face the need to detect the text 
charset/encoding in order to correctly parse it, you realize that it's an 
unnecessary burden.

So, the short answer is: avoid html entities in dynamic controls, check the 
error that make php "crash" with accented characters.

Original comment by ctrlal...@gmail.com on 24 Aug 2013 at 9:52

Attachments:

GoogleCodeExporter commented 9 years ago
This is the stack trace.

[Fri Aug 23 15:13:54 2013] [error] [client 127.0.0.1] PHP Fatal error:  
Uncaught exception 'Exception' with message 'JSON error (5): Malformed UTF-8 
characters, possibly incorrectly encoded' in 
/home/marco/NetBeansProjects/Prado-trunk/framework/Web/Javascripts/TJavaScript.p
hp:268\nStack trace:\n#0 
/home/marco/NetBeansProjects/Prado-trunk/framework/Web/Javascripts/TJavaScript.p
hp(223): TJavaScript::checkJsonError()\n#1 
/home/marco/NetBeansProjects/Prado-trunk/framework/Web/UI/ActiveControls/TActive
PageAdapter.php(350): TJavaScript::jsonEncode(Array)\n#2 
/home/marco/NetBeansProjects/Prado-trunk/framework/Exceptions/TErrorHandler.php(
136): TCallbackErrorHandler->displayException(Object(TPhpErrorException))\n#3 
/home/marco/NetBeansProjects/Prado-trunk/framework/TApplication.php(1135): 
TErrorHandler->handleError(Object(TApplication), 
Object(TPhpErrorException))\n#4 
/home/marco/NetBeansProjects/Prado-trunk/framework/TApplication.php(416): 
TApplication->onError(Object(TPhpErrorException))\n#5 
/home/marco/NetBeansProjects/SitoWebSalvaeuro/src/index.php(21): 
TApplication->run()\n#6 {main}\n  throw in 
/home/marco/NetBeansProjects/Prado-trunk/framework/Web/Javascripts/TJavaScript.p
hp on line 268, referer: http://local__myapp/index.php?page=myapp.MakeMeCrash

:/

Original comment by marco.ba...@gmail.com on 24 Aug 2013 at 11:21

GoogleCodeExporter commented 9 years ago
Ok so this is what's going on:
 * some code in the page is triggering a php error
 * prado translates the error to a TPhpErrorException
 * prado's exception handler is trying to display the typical "Exception occurred" page
 * the exception message (php's error message) contains a character that is not valid UTF-8, and the application's globalization module doesn't have the Charset property set (so the character is not being translated from a foreign charset to UTF-8).
 * the invalid UTF-8 string get passed to json_encode(), that triggers a second exception
 * prado won't catch this second exception to avoid a loop

What can cause this? My guess is that one of your source files is not encoded 
using UTF-8 while the application declares it should (or doesn't declare it at 
all: UTF-8 is prado's default encoding).
Try checking with file --mime:

Lapidus:~ fab$ file --mime test.php 
test.php: text/x-php; charset=utf-8
Lapidus:~ fab$ file --mime test.php 
test.php: text/x-php; charset=iso-8859-1

Original comment by ctrlal...@gmail.com on 25 Aug 2013 at 1:33

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago

Original comment by ctrlal...@gmail.com on 3 Sep 2013 at 10:20