Why does jQuery 1.4.2 compressed have a syntax error? - javascript

I always have noticed this, including in versions before as well. About half way through jQuery's compressed version you'll see some regex:
[^[\]]*\]|['"][^'"]*['"]|[^[\]'"]+)+\]|\\.|[^
The error appears to be at ['"]
I'm sure it's not really a syntax error, but all my code editors recognize it as one, which makes development a pain if I try to combine JavaScript files. Does anyone know what's going on here?

It's a character entity in a regular expression, as specified by the square brackets. There are no restrictions on quote characters in them. All that's going on is buggy syntax highlighting. Ask the developer of your editor.

your code editor sucks, this isnt a syntax error if its inside of a regex literal, which i suspect it is.
the code editor you use probably doesnt support regex literals properly, and that its a string , which would cause the error

Related

Syntax error on regular expression in ExtendScript (Javascript ECMA-262 — Verison 3) [duplicate]

I have a regular expression testing for numbers(0-9) and/or forward slashes (/). It looks like this:
/^[0-9/]+$/i.test(value)
Now I believe this to be correct, but the eclipse javascript validator disagrees:
Syntax error on token "]", delete this token
I suppose this is because the separator/delimiter is / and eclipse 'thinks' the regex is finished (and therefore a ] would be unexpected).
We can satisfy eclipse by escaping the / like so:
/^[0-9\/]+$/i.test(value)
Note that both versions work for me.
My problem with this is:
As far as I know I do not need to escape the forward slash specifically in that range. It might be situation specific (as in, for javascript it is the used delimiter).
Although they both appear to be working, I'd rather use the 'correct' version because of behaviour in different environments, and, well.. because correct and all :)
Does anyone know what I'm supposed to do? Escape or not? I did not find any reputable site that told me to escape the / in a range, but the Eclipse-validator is probably not completely stupid...
The standard clearly says you can put anything unescaped in a character class except \, ] and newline:
RegularExpressionClassChar ::
RegularExpressionNonTerminator but not ] or \
RegularExpressionBackslashSequence
RegularExpressionNonTerminator ::
SourceCharacter but not LineTerminator
( http://es5.github.com/#x7.8.5 ). No need to escape /.
On the other side, I personally would escape everything when in doubt, just to make less smart parsers happy.

Compilation error caused by trailing commas in javascript

edit: I didn't make it clear. I'm using play framework.
I have compilation error as follows:
"Parse error. IE8 (and below) will parse trailing commas in array and object literals incorrectly. If you are targeting newer versions of JS, set the appropriate language_in option."
But I can't find such an option to change language options. How can I get rid of this compilation error?
I can't modify js file - it is generated and is huge. Also, I really don't care about IE8 and below.
It would be great if someone could help me.

Advanced Javascript Obfuscation

I've been training heavily in JS obfuscation, starting to know my way around all advanced concepts, but I recently found an obfuscated code, I believe it is some form of "Native Javascript Code", I just can't find ANY documentation on this type of obfuscation :
Here is a small extract :
'\141\75\160\162\157\155\160\164\50\47\105\156\164\162\145\172\40'
It is called this way :
eval(eval('\141\75\160\162\157\155\160\164\50\47\105\156\164\162\145\172\40'))
Since the code is the work of another and I encoutered it in a JS challenge I'm not posting the full code, so the example I gave won't work, but the full code does work.
So here is my question:
What type of code is this? And where can I learn more about it?
Any suggestions appreciated :)
It's just a string with the characters escaped. You can read it in the JavaScript console in any browser:
console.log('\141\75\160\162\157\155\160\164\50\47\105\156\164\162\145\172\40')
will print:
"a=prompt('Entrez "
It's just escaped characters, one part outputting the string of a query and another actually running the returned string - try calling it in a console.
eval('\160\162\157\155\160\164\50\47\105\156\164\162\145\172\47\51')
Might help?
These numbers is the ascii codes (http://www.asciitable.com/index/asciifull.gif) of characters (in Octal representation).
You can convert it to characters. This is used when somebody wants to make an XSS attack, or wants to hide the js code.
So the string what you written represents:
a=prompt('Entrez
The js engines, browsers can translate the octal format to the 'real' string. With eval function it could run. (in case the 'translated' code has no syntax errors)

CKEDITOR.instance[x].setData not working in IE

Ok, I'm using the CKEditor in a web application. One thing I need to do it set the text in the text area. I've been using the line:
CKEDITOR.instances.setData(html);
...where html is a varible containing HTML.
This works fine in Chrome & Firefox, but not at all in Internet Explorer or Safari.
Can anyone provide an insight as to why, or suggest a work-around?
Many thanks in advance! :-)
Make sure to strip all newlines from the string you pass into setData(). An exception is thrown if you don't, with a message about an unterminated string. The newline characters used by CKEditor are the UNIX-style of \n (in other words, not the DOS version: \r\n).
The newline apparently throws off the parser, making it think that it's the end of the statement.
Also note that if you call getData() to get that value you just set again, CKEditor puts the line breaks and tabs back into it. You'll need to strip them out again if you need to set that value back using setData(). I use a regexp pattern like this to strip out the newlines (and tabs just for completeness):
[\n\t]+
Also make sure that if you use the regular expression to strip them, you need to make sure that the pattern matching will match the \n character (called "single-line" mode in .NET, but I don't know what you're using).

Javascript major mode in Emacs

Which javascript major modes exist in Emacs, and what are their key-features ?
js2-mode: a new JavaScript mode for Emacs This is part of a larger
project, in progress, to permit writing Emacs extensions in JavaScript
instead of Emacs-Lisp.
Features: M-x customize Accurate syntax
highlighting Indentation Code folding
Comment and string filling Syntax errors Strict
warnings jsdoc highlighting
http://steve-yegge.blogspot.com/2008/03/js2-mode-new-javascript-mode-for-emacs.html
With some documentation.
I think what you want is this:
http://www.corybennett.org/download/javascript-mode.el
Then again, maybe this what you are looking for?
or this?
People seem to prefer (at least given the highest rated answer):
Updated: http://steve-yegge.blogspot.com/2008/03/js2-mode-new-javascript-mode-for-emacs.html
I use Steve Yegge's js2-mode, and like it a lot. It's quite configurable, its indentation ideas match mine, and most impressively it has a full JavaScript parser in it, so it can alert me to syntax errors as I type (indispensable for little things like trailing commas in property lists that bork IE).
Espresso mode is supposed to be quite good as well.

Categories