Apparently you are unable to quote properly. That does not bode well for
your record in this newsgroup.
Maybe if you had heard me when I said it you would had notice my lack
of seriousness.
Whatever.
Now, that would have been interesting hearing after I said that!
It should be your reference, too, as it would prevent you from jumping to
conclusions, like:
15.1.2.1 eval (x)
When the eval function is called with one argument x, the following
steps are taken:
1. If x is not a string value, return x.
2. Parse x as a Program. If the parse fails, throw a SyntaxError
exception (but see also clause 16).
[...]
PointedEars:
There is no "correct" length, ECMAScript Programs are of arbitrary length.
In what I wrote, v is supposed to be a string!
Strings are also of arbitrary length (only limited by available heap memory)
in ECMAScript implementations. Can't you read?
True, I have corrected myself 4 minutes after, 4 hours 41 minutes before
your reply. (Has anyone told you already that you shouldn't use Google
Groups for posting to Usenet if you can't handle it?)
it IS a string, check #1. If its not returned, its a string.
As I said in my correction, that doesn't matter here, though. The string,
when passed (as here), is parsed *as if* it was an ECMAScript Program, and
both are specified (and implemented) to be of arbitrary length (else we
would not have to deal with about 28 KiB of Prototype.js junk, for example.)
Do you have any conclusive evidence that whitespace matters in JScript
5.7.5xxx Object or Array initializers, and especially in a string to be
passed to eval(), IOW that these particular versions of this particularfour
implementation are not standards-compliant in that regard?
No I don't. I should have said invalid character... but, How would you
explain then, that the string the guy gets is the "same"
as the hardcoded one but gets the error? could be a not closed [ but
he says its the same string!
He could be mistaken. Trimming anything client-side isn't supposed to solve
the problem in the long run, though. The server output has to be fixed, if
erroneous, instead.
I haven't seen you share solutions here.
There are no solutions to share when the input (or here: the output) is that
uncertain.
Not just any string; it must be in the form of an ECMAScript(-compliant)
Program or a SyntaxError exception is thrown. And if eval() is called in an
inappropriate way, implementations may throw an EvalError exception. See
the ECMAScript Language Specification, Edition 3 Final, section 15.1.2.1.
Interesting.. and how would you get this error:
Microsoft JScript compilation error: Expected ']'
Another distinct possibility is that the OP did not post the exact value.
Since there are not a trim method defined on any popular browser that
I know...
See above. The FAQ has one (and it is rather easy to devise one by
yourself), so that would not matter. It is the method of debugging that is
in question here, though, not how it is accomplished.
I was thinking in something on the line:
var s=("\n\n {'results': [ {'id': 4}]} \n\n"+String.fromCharCode
(1000)),e;
Why you parenthesize the assigned value of `s' here, remains a mystery.
//this:
e=eval("("+s.substring(s.indexOf('{'),s.lastIndexOf('}')+1)+")");
As I said, garbage before or after is a possibility. But given this string
`s', trimming it is unnecessary as whitespace (such as newlines) is _not_
garbage, and it is irrelevant outside of literals in ECMAScript Programs,
until you provide proof to the contrary for one implementation. So far,
you have only vented a lot of hot air here, like:
// Instead of this
e=eval("("+s+")"); // Check what error firefox gets here,
interesting...
FTR, the error message I get in Firebug is:
| SyntaxError: missing ) in parenthetical
That's interesting, indeed, because
(
{'results': [ {'id': 4}]}
Ϩ)
("Ϩ" is the return value of String.fromCharCode(1000) or U+03E8, COPTIC
CAPITAL LETTER HORI, but that matters little as long it isn't whitespace)
just isn't a syntactically valid ECMAScript Program. Why should it?
// Still no code from you.
See above.
No, not at all and Peter's reply confirms I'm not the only one
shooting at invalid (invisible) characters.
Indeed, you should read my postings more thoroughly. Does "distinct
possibility" ring a bell?
My point was that because he is asking how to solve this on JS help
him in JS.
Your argument is flawed. If any such output is possible, the server output
must be checked and fixed there instead.
Would also be better if he finds the error in JS first.
Second step before the first one, likely to constitute a waste of time.
At least mentally, apparently much older than you.
PointedEars