JSCoverage
code coverage for JavaScript

Bug #39 - Instrumenting a site that uses Microsoft AJAX in proxy mode fails with ‘invalid character'

Submitted by: fpintos
Date submitted: 2011-08-22 18:16:00 UTC
Status: Open
Trying to instrument a site that uses Microsoft AJAX using jscoverage in proxy 
mode fails with ‘invalid character’.

Repro:
-	download 0.5.1 from http://siliconforks.com/jscoverage/download.html
-	run “jscoverage-server.exe --verbose –proxy”
-	force browser to use 127.0.0.1:8080 as proxy
-	open http://www.asp.net/ajaxlibrary/act_AlwaysVisible.ashx
-	watch the server fail with SyntaxError: illegal character
o	URL in this case is the hash from ScriptManager, but a simpler page 
reveals this to happen with just MicrosoftAjax.js.

Same results if you run jscoverage.exe directly on MicrosoftAjax.js.

If you own the site then at least there's a workaround, which is to prettify the 
file beforehand. When the file is expanded with 'ajaxmin -pretty' then 
jscoverage is happy with it:

Repro, assuming retail MicrosoftAjax.js in d:\temp:

D:\temp\cover>copy ..\MicrosoftAjax.js
        1 file(s) copied.

D:\temp\cover>d:\jscoverage-0.5.1\jscoverage.exe d:\temp\cover d:\temp\cover2
jscoverage:MicrosoftAjax.js:1: SyntaxError: illegal character
jscoverage: parse error in file MicrosoftAjax.js

D:\temp\cover>ajaxmin -pretty MicrosoftAjax.js > MicrosoftAjax.pretty.js
Microsoft Ajax Minifier - JavaScript and CSS minification and verification 
utility
Copyright 2010 Microsoft Corporation


Minifying file 'MicrosoftAjax.js'...
Original Size: 101547 bytes; reduced size: 157173 bytes (-54.8% minification)
Gzip of output approximately 34280 bytes (78.2% compression)


D:\temp\cover>del MicrosoftAjax.js

D:\temp\cover>d:\jscoverage-0.5.1\jscoverage.exe d:\temp\cover d:\temp\cover2


D:\temp\cover>dir \temp\cover2
 Volume in drive D has no label.
 Volume Serial Number is D09F-409A

 Directory of D:\temp\cover2

08/22/2011  11:05 AM    <DIR>          .
08/22/2011  11:05 AM    <DIR>          ..
08/22/2011  11:05 AM             1,157 jscoverage-highlight.css
08/22/2011  11:05 AM             2,011 jscoverage-ie.css
08/22/2011  11:05 AM               425 jscoverage-throbber.gif
08/22/2011  11:05 AM             6,342 jscoverage.css
08/22/2011  11:05 AM             6,609 jscoverage.html
08/22/2011  11:05 AM            33,286 jscoverage.js
08/22/2011  11:04 AM                 0 MicrosoftAjax.js
08/22/2011  11:05 AM         1,128,521 MicrosoftAjax.pretty.js
               8 File(s)      1,178,351 bytes
               2 Dir(s)  189,092,405,248 bytes free

Submitted by: fpintos
Date submitted: 2011-08-22 18:33:33 UTC
Hum...it seems that the problem is actually that the file uses UTF-8 encoding 
and jscoverage doesn't like the encoding characters at the beginning of the 
file.

Saving the files with ANSI encoding make jscoverage happy.
Submitted by: Ed
Date submitted: 2011-08-22 20:44:47 UTC
JSCoverage's character encoding detection is not very sophisticated: if a
JavaScript file is UTF-8, it will have to be served with the header
"Content-Type: text/javascript; charset=UTF-8" or the jscoverage-server might
get confused.

Add a comment

Your name:
Your email address (optional - will never be displayed):
Comment:
Attachment (optional - maximum 64 KiB):
Copyright © 2008 Silicon Forks siliconforks.com
siliconforks@siliconforks.com