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.
testString: assert(code.match(/\.concat/g));
- 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.
testString: assert(JSON.stringify(first) === JSON.stringify([1, 2, 3]));
- 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.
testString: assert(globalTitle === "Winter Is Coming");
- 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>.
testString: assert(urlSlug("Winter Is Coming") === "winter-is-coming");
- 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.
testString: assert(code.match(/\.join/g));
- 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.
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>.

View File

@ -26,7 +26,7 @@ tests:
- 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]));
- 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>.
testString: assert(JSON.stringify(new_s) === JSON.stringify([23, 65, 5]));
- 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.
testString: assert(code.match(/\.slice/g));
- 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.
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>.

View File

@ -7,16 +7,19 @@ forumTopicId: 16079
---
## Description
<section id='description'>
Flatten a nested array. You must account for varying levels of nesting.
</section>
## Instructions
<section id='instructions'>
</section>
## Tests
<section id='tests'>
```yml
@ -30,12 +33,13 @@ tests:
- text: <code>steamrollArray([1, {}, [3, [[4]]]])</code> should return <code>[1, {}, 3, 4]</code>.
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.
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>
## Challenge Seed
<section id='challengeSeed'>
<div id='js-seed'>
@ -50,13 +54,11 @@ steamrollArray([1, [2], [3, [[4]]]]);
</div>
</section>
## Solution
<section id='solution'>
<section id='solution'>
```js
function steamrollArray(arr) {

View File

@ -24,7 +24,7 @@ tests:
- text: <code>result</code> should equal to <code>"Hello, World!"</code>
testString: assert(result == "Hello, World!");
- 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.
testString: assert(!code.match(/result\s*=\s*".*?"/));