Closed
Bug 280579
Opened 20 years ago
Closed 20 years ago
Eval fails with "unterminated string literal" error if more than 128 characters used
Categories
(Core :: DOM: Core & HTML, defect)
Tracking
()
People
(Reporter: edwinwo, Unassigned)
Details
Attachments
(2 files)
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.7.5) Gecko/20041107 Firefox/1.0 Build Identifier: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.7.5) Gecko/20041107 Firefox/1.0 The following code works fine - until you add a single character anywhere to the body text, for example, change Soap to Soaps. Then javascript console reports an "unterminated string literal" error. There are 128 characters in the string that is being evaluated - one more causes the error. Code executes fine with any length string in IE. <html> <head> <script type="text/javascript"> function ol(){ evalServerResponse(); } function evalServerResponse(){ transxdata = document.body.innerHTML; alert(transxdata); //alert(transxdata.length); if (transxdata.length > 0) { var transact = transxdata.split("|"); //alert(transact.length); for (var i=0; i< transact.length; i++){ //alert(transact[i] + ";"); eval(transact[i] + ";"); } } } function AddRow(arr){ tmp = arr.length; for (var i=1; i< tmp; i++){ alert(arr[i]); } } </script> <head> <body onload='ol()'>AddRow(["234567890123456789","Joe","Soaps","555-342522","For the benefit of Mr Kite there will be a show tonight on trampoline"]) </body> <html> Reproducible: Always Steps to Reproduce: 1. Add in a character anywhere inside a quote string in the body text, eg Soap to Soaps or Joe to Joey, it doesn't matter where - the TOTAL number of characters seems to be the problem ... 2. Run the program 3. If less than 128 chars, the different fields will alert correctly, otherwise the program stops, and the javascript console reports a ""unterminated string literal" error. I use eval to pick up responses from a server - the 128 char limit on eval is a major bug for me - no easy workaround.
Updated•20 years ago
|
Severity: blocker → normal
Updated•20 years ago
|
Assignee: firefox → general
Component: General → JavaScript Engine
Product: Firefox → Core
QA Contact: general → pschwartau
Version: unspecified → Trunk
Comment 1•20 years ago
|
||
Comment 2•20 years ago
|
||
Comment 3•20 years ago
|
||
There is no magic 128 character limit, that blatant a bug would have been found by now. Notice that the error in the JS console shows the unterminated string. It ends without a quote, with a newline, like so >>> "For the Something in the parser or the DOM is splitting document.body.innerHTML up based on magic 128 (or some such) numbers, and you've found the threshold. /be
Assignee: general → general
Status: UNCONFIRMED → NEW
Component: JavaScript Engine → DOM: Level 0
Ever confirmed: true
QA Contact: pschwartau → ian
Comment 4•20 years ago
|
||
> There is no magic 128 character limit, that blatant a bug would have been found
I meant "limit in eval", natch.
/be
Comment 5•20 years ago
|
||
Note that innerHTML expects its output to be parsed by an HTML parser, so using it for something like this is _really_ chancy. If nothing else, it will happily convert some characters to entities as needed... *** This bug has been marked as a duplicate of 89780 ***
Status: NEW → RESOLVED
Closed: 20 years ago
Resolution: --- → DUPLICATE
You need to log in
before you can comment on or make changes to this bug.
Description
•