<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
<html>
<head>
<link rel="stylesheet" href="../js/resources/js-test-style.css">
<script src="../js/resources/js-test-pre.js"></script>
</head>
<body>
<p>Test for <a href="http://bugs.webkit.org/show_bug.cgi?id=41862">bug 41862</a>:
XPath substring function is broken when passing NaN as the position parameter.</p>
<div id="console"></div>
<script>
shouldBe("document.evaluate(\"substring('12345', number(\'NaN\'))\", document, null, XPathResult.STRING_TYPE, null).stringValue", "''");
shouldBe("document.evaluate(\"substring('12345', number(\'NaN\'), 3)\", document, null, XPathResult.STRING_TYPE, null).stringValue", "''");
<!-- -2147483645 represents MIN_INT-3 which when passed through the original substring function before the fix for 41862 landed caused an overflow and wrap to 2. That meant that this case was effectively calling substring('12345', MIN_INT, 2) and returning 12, rather than the empty string which the NaN should have triggered.. -->
shouldBe("document.evaluate(\"substring('12345', number(\'NaN\'), -2147483645)\", document, null, XPathResult.STRING_TYPE, null).stringValue", "''");
shouldBe("document.evaluate(\"substring('12345', number(\'NaN\'), number(\'NaN\'))\", document, null, XPathResult.STRING_TYPE, null).stringValue", "''");
var successfullyParsed = true;
</script>
<script src="../js/resources/js-test-post.js"></script>
</body>
</html>