Work at SourceForge, help us to make it a better place! We have an immediate need for a Support Technician in our San Francisco or Denver office.

Close

#515 ActiveXObject is incorrectly case sensitive

closed
Ahmed Ashour
None
5
2014-03-08
2007-08-29
Dan Fabulich
No

Create an HTML file called "activexbug.html" containing the following:

<html>
<head>
ActiveXObject bug
<script>
function onLoad() {
new ActiveXObject("MSXML2.XmlHttp");
}
</script>
</head>
<body onload="onLoad()">
</body>
</html>

Load it in IE7 with script errors enabled. There will be no JS exceptions.

Load it in HTMLUnit like this:

final WebClient webClient = new WebClient(BrowserVersion.INTERNET_EXPLORER_7_0);
final HtmlPage page = (HtmlPage) webClient.getPage("file:///C:/temp/activexbug.html");
System.out.println(page.getTitleText());

You'll get a JS error:

com.gargoylesoftware.htmlunit.ScriptException: ActiveXObject Error: no value for MSXML2.XmlHttp. (script in file:/C:/activexbug.html from (4, 9) to (0, 0)#2)

This is happening because IE7 is case-insensitive when it comes to instantiating ActiveXObject, but HTMLUnit is being inappropriately case-sensitive. The fix is to make ActiveXObject.java case insensitive, by modifying isXMLHttpRequest on line 132:

static boolean isXMLHttpRequest(String name) {
    if (name == null) return false;
    name = name.toLowerCase();
    return ("microsoft.xmlhttp".equals(name) || name.startsWith("msxml2.xmlhttp"));
}

Discussion

  • Ahmed Ashour
    Ahmed Ashour
    2007-08-29

    Logged In: YES
    user_id=950730
    Originator: NO

    Fixed in SVN, many thanks.