View Full Version : [UNKNOWN][3.0.3] JSON parser fails when submitting with fileUpload option

6 Dec 2009, 9:56 AM
ExtJS 3.0.3

I have a form with upload field. I noticed that if my response data contains the tag <br/>, the json parser fails with an error "unterminated regular expression literal".

If I remove the option fileUpload:true, all works OK. I assume that this is because, in the case of the file uploading, the data submission is performed over a hidden iframe and parsed in another way than in the case of the normal submission.

The error can be reproduced as follows. The example "file-upload" in the ExtJS distribution contains the file file-upload.php. Modify it as follows

$file = empty($_FILES['photo-path']['name']) ? "-" : $_FILES['photo-path']['name'];
echo '{success:true, file:' . json_encode('line 1<br/>line 2:' . $file).'}';

Not try to upload a file. The firefox(firebug) reports the error "unterminated regular expression literal".

Now remove the option fileUpload:true and try to submit the form. The response message is correctly shown and no error occurs.

The slash in the BR tag must not be escaped on the PHP level. At this place, it is an absolutely correct string.

6 Dec 2009, 11:22 AM
The response from a file upload needs to be valid HTML (Content-Type: text/html).

Either encode the response, e.g.

{success: true, file: 'line 1&lt;br /&gt;line2'}

or put the response in a textarea, e.g.

<html><body><textarea>{success: true, file: 'line 1<br />line2'}</textarea></body></html>