Why do multiple decimals in a JavaScript list throw a 'missing ] after element list' error?
I have two buttons that I use to diff some revisions in CVS:
Button A:
<input type="button" onclick="javascript:var from = get_diff_from(this.form,2); var to = get_diff_to(this.form,2); parent.show_file('196382', 'telecom.mod', 'teleTWTA.c', from, to, 'webtools/cvsweb/cvsweb.cgi', 'fsw',
get_chg_array([1.2,1.3], [0,196382], from, to));" value="Diff teleTWTA.c">
Button B:
<input type="button" onclick="javascript:var from = get_diff_from(this.form,3); var to = get_diff_to(this.form,3); parent.show_file('196383', 'telecom.mod/te开发者_高级运维st/solaris.ut/telecom_twta.exe', 'ut_teleTWTA.c', from, to, 'webtools/cvsweb/cvsweb.cgi',
'fsw', get_chg_array([1.1.1.1,1.2], [0,196383], from, to));" value="Diff ut_teleTWTA.c">
Button A works fine, but button B chokes on clicking, and throws:
'missing ] after element list'.
The only explanation I can come up with is the longer CVS revision number (1.1.1.1) in button B. Why would JS break on this, and how can I fix it?
The value 1.1.1.1
should be enclosed in quotes, as it is a string, not a valid number. Otherwise, it will try to be evaluated as an object with nested properties named 1
.
EDIT: Actually, since 1
is not a valid javascript variable name, I'm not exactly sure how the runtime will attempt to evaluate 1.1.1.1
. In any case, it's certainly not valid.
精彩评论