checkExact falsely returns true
mcolburn opened this issue · 0 comments
mcolburn commented
In index.js, the function checkExact falsely returns true.
No matter what word I check, it returns true.
The issue is in this portion of the code:
if ("COMPOUNDMIN" in this.dict.flags && word.length >= this.dict.flags.COMPOUNDMIN) {
for (var i = 0, _len = this.dict.compoundRules.length; i < _len; i++) {
if (word.match(this.dict.compoundRules[i])) {
return true;
}
}
}
if this.dict.compoundRules[i] is undefined, then
if (word.match(this.dict.compoundRules[i]))
will return true, which is erroneous. The issue is that supplying string.match with undefined as the argument will result in a value of true.
You can see this using the following:
var word = 'hi';
console.log(word.match(undefined);
I suggest that the checkExact code should be modified to:
if ("COMPOUNDMIN" in this.dict.flags && word.length >= this.dict.flags.COMPOUNDMIN) {
for (var i = 0, _len = this.dict.compoundRules.length; i < _len; i++) {
if ( ! this.dict.compoundRuleCodes[i] === undefined) {
if (word.match(this.dict.compoundRules[i])) {
return true;
}
}
}
}