-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
40 lines (40 loc) · 1.41 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
const db=require("@spellcheckjs/spellcheckjs");
const applyCorrections=function(input) {
let output=input;
let loopCount=0;
Object.keys(db).forEach(entryName => {
let entry=db[entryName];
while(output.includes(entryName)) {
loopCount++;
if(loopCount==100) {
console.warn("SpellCheckJS has run 100 times.");
}
else if(loopCount==200) {
console.warn("SpellCheckJS has run 200 times. You may have supplied maliciously crafted data to the function.");
}
output=output.replace(entryName,entry);
}
// This while loop is where the biggest risk is. With a malicious entry, a user could dOS clients by repetitively increasing input length. Thus the need for thorough submission review.
});
return output;
};
const isCorrectlySpelled=function(input) {
try {
Object.keys(db).forEach(entryName => {
let entry=db[entryName];
if(input.includes(entryName)) {
throw new Error();
};
// This while loop is where the biggest risk is. With a malicious entry, a user could dOS clients by repetitively increasing input length. Thus the need for thorough submission review.
});
return true
}
catch(e) {
return false;
}
}
const SpellCheckJS={
db,
applyCorrections
};
module.exports=SpellCheckJS;