fix: improve test regex to validate disallowed methods that can be bypassed by prototype reassignments and/or otherwise (#38214)

* fix: improve test regex to validate disallowed methods that can be bypassed by prototype reassignments and/or otherwise

* fix: fixing regex pattern
This commit is contained in:
Hassaan Pasha
2020-03-26 20:13:34 +05:00
committed by GitHub
parent bb7a50e341
commit 4fbce07792
13 changed files with 18 additions and 16 deletions

View File

@ -33,7 +33,7 @@ tests:
- text: Your code should use the <code>concat</code> method. - text: Your code should use the <code>concat</code> method.
testString: assert(code.match(/\.concat/g)); testString: assert(code.match(/\.concat/g));
- text: Your code should not use the <code>push</code> method. - text: Your code should not use the <code>push</code> method.
testString: assert(!code.match(/\.push/g)); testString: assert(!code.match(/\.?[\s\S]*?push/g));
- text: The <code>first</code> array should not change. - text: The <code>first</code> array should not change.
testString: assert(JSON.stringify(first) === JSON.stringify([1, 2, 3])); testString: assert(JSON.stringify(first) === JSON.stringify([1, 2, 3]));
- text: The <code>second</code> array should not change. - text: The <code>second</code> array should not change.

View File

@ -29,7 +29,7 @@ tests:
- text: The <code>globalTitle</code> variable should not change. - text: The <code>globalTitle</code> variable should not change.
testString: assert(globalTitle === "Winter Is Coming"); testString: assert(globalTitle === "Winter Is Coming");
- text: Your code should not use the <code>replace</code> method for this challenge. - text: Your code should not use the <code>replace</code> method for this challenge.
testString: assert(!code.match(/\.replace/g)); testString: assert(!code.match(/\.?[\s\S]*?replace/g));
- text: <code>urlSlug("Winter Is Coming")</code> should return <code>"winter-is-coming"</code>. - text: <code>urlSlug("Winter Is Coming")</code> should return <code>"winter-is-coming"</code>.
testString: assert(urlSlug("Winter Is Coming") === "winter-is-coming"); testString: assert(urlSlug("Winter Is Coming") === "winter-is-coming");
- text: <code>urlSlug(" Winter Is &nbsp;Coming")</code> should return <code>"winter-is-coming"</code>. - text: <code>urlSlug(" Winter Is &nbsp;Coming")</code> should return <code>"winter-is-coming"</code>.

View File

@ -31,7 +31,7 @@ tests:
- text: Your code should use the <code>join</code> method. - text: Your code should use the <code>join</code> method.
testString: assert(code.match(/\.join/g)); testString: assert(code.match(/\.join/g));
- text: Your code should not use the <code>replace</code> method. - text: Your code should not use the <code>replace</code> method.
testString: assert(!code.match(/\.replace/g)); testString: assert(!code.match(/\.?[\s\S]*?replace/g));
- text: <code>sentensify("May-the-force-be-with-you")</code> should return a string. - text: <code>sentensify("May-the-force-be-with-you")</code> should return a string.
testString: assert(typeof sentensify("May-the-force-be-with-you") === "string"); testString: assert(typeof sentensify("May-the-force-be-with-you") === "string");
- text: <code>sentensify("May-the-force-be-with-you")</code> should return <code>"May the force be with you"</code>. - text: <code>sentensify("May-the-force-be-with-you")</code> should return <code>"May the force be with you"</code>.

View File

@ -26,7 +26,7 @@ tests:
- text: <code>new_s</code> should equal <code>[46, 130, 196, 10]</code>. - text: <code>new_s</code> should equal <code>[46, 130, 196, 10]</code>.
testString: assert(JSON.stringify(new_s) === JSON.stringify([46, 130, 196, 10])); testString: assert(JSON.stringify(new_s) === JSON.stringify([46, 130, 196, 10]));
- text: Your code should not use the <code>map</code> method. - text: Your code should not use the <code>map</code> method.
testString: assert(!code.match(/\.map/g)); testString: assert(!code.match(/\.?[\s\S]*?map/g));
``` ```

View File

@ -24,7 +24,7 @@ tests:
- text: <code>new_s</code> should equal <code>[23, 65, 5]</code>. - text: <code>new_s</code> should equal <code>[23, 65, 5]</code>.
testString: assert(JSON.stringify(new_s) === JSON.stringify([23, 65, 5])); testString: assert(JSON.stringify(new_s) === JSON.stringify([23, 65, 5]));
- text: Your code should not use the <code>filter</code> method. - text: Your code should not use the <code>filter</code> method.
testString: assert(!code.match(/\.filter/g)); testString: assert(!code.match(/\.?[\s\S]*?filter/g));
``` ```

View File

@ -32,7 +32,7 @@ tests:
- text: Your code should use the <code>slice</code> method. - text: Your code should use the <code>slice</code> method.
testString: assert(code.match(/\.slice/g)); testString: assert(code.match(/\.slice/g));
- text: Your code should not use the <code>splice</code> method. - text: Your code should not use the <code>splice</code> method.
testString: assert(!code.match(/\.splice/g)); testString: assert(!code.match(/\.?[\s\S]*?splice/g));
- text: The <code>inputCities</code> array should not change. - text: The <code>inputCities</code> array should not change.
testString: assert(JSON.stringify(inputCities) === JSON.stringify(["Chicago", "Delhi", "Islamabad", "London", "Berlin"])); testString: assert(JSON.stringify(inputCities) === JSON.stringify(["Chicago", "Delhi", "Islamabad", "London", "Berlin"]));
- text: <code>nonMutatingSplice(["Chicago", "Delhi", "Islamabad", "London", "Berlin"])</code> should return <code>["Chicago", "Delhi", "Islamabad"]</code>. - text: <code>nonMutatingSplice(["Chicago", "Delhi", "Islamabad", "London", "Berlin"])</code> should return <code>["Chicago", "Delhi", "Islamabad"]</code>.

View File

@ -7,16 +7,19 @@ forumTopicId: 16079
--- ---
## Description ## Description
<section id='description'> <section id='description'>
Flatten a nested array. You must account for varying levels of nesting. Flatten a nested array. You must account for varying levels of nesting.
</section> </section>
## Instructions ## Instructions
<section id='instructions'> <section id='instructions'>
</section> </section>
## Tests ## Tests
<section id='tests'> <section id='tests'>
```yml ```yml
@ -30,12 +33,13 @@ tests:
- text: <code>steamrollArray([1, {}, [3, [[4]]]])</code> should return <code>[1, {}, 3, 4]</code>. - text: <code>steamrollArray([1, {}, [3, [[4]]]])</code> should return <code>[1, {}, 3, 4]</code>.
testString: assert.deepEqual(steamrollArray([1, {}, [3, [[4]]]]), [1, {}, 3, 4]); testString: assert.deepEqual(steamrollArray([1, {}, [3, [[4]]]]), [1, {}, 3, 4]);
- text: Your solution should not use the <code>Array.prototype.flat()</code> or <code>Array.prototype.flatMap()</code> methods. - text: Your solution should not use the <code>Array.prototype.flat()</code> or <code>Array.prototype.flatMap()</code> methods.
testString: assert(!code.match(/\.flat\([\s\S]*?\)/) && !code.match(/\.flatMap\([\s\S]*?\)/)); testString: assert(!code.match(/\.?[\s\S]*?flat/) && !code.match(/\.?[\s\S]*?flatMap/));
``` ```
</section> </section>
## Challenge Seed ## Challenge Seed
<section id='challengeSeed'> <section id='challengeSeed'>
<div id='js-seed'> <div id='js-seed'>
@ -50,13 +54,11 @@ steamrollArray([1, [2], [3, [[4]]]]);
</div> </div>
</section> </section>
## Solution ## Solution
<section id='solution'>
<section id='solution'>
```js ```js
function steamrollArray(arr) { function steamrollArray(arr) {

View File

@ -24,7 +24,7 @@ tests:
- text: <code>result</code> should equal to <code>"Hello, World!"</code> - text: <code>result</code> should equal to <code>"Hello, World!"</code>
testString: assert(result == "Hello, World!"); testString: assert(result == "Hello, World!");
- text: Your solution should not use the <code>String.prototype.trim()</code> method. - text: Your solution should not use the <code>String.prototype.trim()</code> method.
testString: assert(!code.match(/\.trim\([\s\S]*?\)/)); testString: assert(!code.match(/\.?[\s\S]*?trim/));
- text: The <code>result</code> variable should not be set equal to a string. - text: The <code>result</code> variable should not be set equal to a string.
testString: assert(!code.match(/result\s*=\s*".*?"/)); testString: assert(!code.match(/result\s*=\s*".*?"/));

View File

@ -31,7 +31,7 @@ tests:
- text: <code>bubbleSort</code> should return an array that is unchanged except for order. - text: <code>bubbleSort</code> should return an array that is unchanged except for order.
testString: assert.sameMembers(bubbleSort([1,4,2,8,345,123,43,32,5643,63,123,43,2,55,1,234,92]), [1,4,2,8,345,123,43,32,5643,63,123,43,2,55,1,234,92]); testString: assert.sameMembers(bubbleSort([1,4,2,8,345,123,43,32,5643,63,123,43,2,55,1,234,92]), [1,4,2,8,345,123,43,32,5643,63,123,43,2,55,1,234,92]);
- text: <code>bubbleSort</code> should not use the built-in <code>.sort()</code> method. - text: <code>bubbleSort</code> should not use the built-in <code>.sort()</code> method.
testString: assert.strictEqual(code.search(/\.sort\(/), -1); testString: assert(!code.match(/\.?[\s\S]*?sort/));
``` ```

View File

@ -29,7 +29,7 @@ tests:
- text: <code>insertionSort</code> should return an array that is unchanged except for order. - text: <code>insertionSort</code> should return an array that is unchanged except for order.
testString: assert.sameMembers(insertionSort([1,4,2,8,345,123,43,32,5643,63,123,43,2,55,1,234,92]), [1,4,2,8,345,123,43,32,5643,63,123,43,2,55,1,234,92]); testString: assert.sameMembers(insertionSort([1,4,2,8,345,123,43,32,5643,63,123,43,2,55,1,234,92]), [1,4,2,8,345,123,43,32,5643,63,123,43,2,55,1,234,92]);
- text: <code>insertionSort</code> should not use the built-in <code>.sort()</code> method. - text: <code>insertionSort</code> should not use the built-in <code>.sort()</code> method.
testString: assert.strictEqual(code.search(/\.sort\(/), -1); testString: assert(!code.match(/\.?[\s\S]*?sort/));
``` ```

View File

@ -33,7 +33,7 @@ tests:
- text: <code>mergeSort</code> should return an array that is unchanged except for order. - text: <code>mergeSort</code> should return an array that is unchanged except for order.
testString: assert.sameMembers(mergeSort([1,4,2,8,345,123,43,32,5643,63,123,43,2,55,1,234,92]), [1,4,2,8,345,123,43,32,5643,63,123,43,2,55,1,234,92]); testString: assert.sameMembers(mergeSort([1,4,2,8,345,123,43,32,5643,63,123,43,2,55,1,234,92]), [1,4,2,8,345,123,43,32,5643,63,123,43,2,55,1,234,92]);
- text: <code>mergeSort</code> should not use the built-in <code>.sort()</code> method. - text: <code>mergeSort</code> should not use the built-in <code>.sort()</code> method.
testString: assert.strictEqual(code.search(/\.sort\(/), -1); testString: assert(!code.match(/\.?[\s\S]*?sort/));
``` ```

View File

@ -30,7 +30,7 @@ tests:
- text: <code>quickSort</code> should return an array that is unchanged except for order. - text: <code>quickSort</code> should return an array that is unchanged except for order.
testString: assert.sameMembers(quickSort([1,4,2,8,345,123,43,32,5643,63,123,43,2,55,1,234,92]), [1,4,2,8,345,123,43,32,5643,63,123,43,2,55,1,234,92]); testString: assert.sameMembers(quickSort([1,4,2,8,345,123,43,32,5643,63,123,43,2,55,1,234,92]), [1,4,2,8,345,123,43,32,5643,63,123,43,2,55,1,234,92]);
- text: <code>quickSort</code> should not use the built-in <code>.sort()</code> method. - text: <code>quickSort</code> should not use the built-in <code>.sort()</code> method.
testString: assert.strictEqual(code.search(/\.sort\(/), -1); testString: assert(!code.match(/\.?[\s\S]*?sort/));
``` ```

View File

@ -29,7 +29,7 @@ tests:
- text: <code>selectionSort</code> should return an array that is unchanged except for order. - text: <code>selectionSort</code> should return an array that is unchanged except for order.
testString: assert.sameMembers(selectionSort([1,4,2,8,345,123,43,32,5643,63,123,43,2,55,1,234,92]), [1,4,2,8,345,123,43,32,5643,63,123,43,2,55,1,234,92]); testString: assert.sameMembers(selectionSort([1,4,2,8,345,123,43,32,5643,63,123,43,2,55,1,234,92]), [1,4,2,8,345,123,43,32,5643,63,123,43,2,55,1,234,92]);
- text: <code>selectionSort</code> should not use the built-in <code>.sort()</code> method. - text: <code>selectionSort</code> should not use the built-in <code>.sort()</code> method.
testString: assert.strictEqual(code.search(/\.sort\(/), -1); testString: assert(!code.match(/\.?[\s\S]*?sort/));
``` ```