Bug15992535.js 1.3 KB

1234567891011121314151617181920212223242526272829
  1. //-------------------------------------------------------------------------------------------------------
  2. // Copyright (C) Microsoft. All rights reserved.
  3. // Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
  4. //-------------------------------------------------------------------------------------------------------
  5. if (this.WScript && this.WScript.LoadScriptFile) { // Check for running in ch
  6. this.WScript.LoadScriptFile("..\\UnitTestFramework\\UnitTestFramework.js");
  7. }
  8. var tests = [
  9. {
  10. name: "Regex parser correctly throws error if too many capturing groups",
  11. body: function () {
  12. assert.doesNotThrow(
  13. // Should succeed. Use 2^15 - 2 pairs of parens, because
  14. // the entire regex always counts as a capturing group.
  15. () => { return new RegExp("(ab)".repeat(0x7ffe)); }
  16. );
  17. assert.throws(
  18. () => { return new RegExp("(ab)".repeat(0x8000)); },
  19. RangeError,
  20. "regex parsing throws when the regex has more than 2^15 - 1 capturing groups",
  21. "Regular expression cannot have more than 32,767 capturing groups"
  22. );
  23. }
  24. }
  25. ];
  26. testRunner.runTests(tests, { verbose: WScript.Arguments[0] != "summary" });