wooorm / franc

Natural language detection
https://wooorm.com/franc/
MIT License
4.12k stars 173 forks source link

TypeError when language not in whiteList #22

Closed danielnaber closed 9 years ago

danielnaber commented 9 years ago

This fails, while it works if no whiteList is specified (the input is Hebrew):

const franc = require('franc');
var language = franc("הפיתוח הראשוני בשנות ה־80 התמקד בגנו ובמערכת הגרפית",
                     { 'whitelist': ['eng'] });
console.log(language);

The error is:

/home/dnaber/nodejs/node_modules/franc/lib/franc.js:240
var min = distances[0][1];
                      ^
TypeError: Cannot read property '1' of undefined
at normalize (/home/dnaber/nodejs/node_modules/franc/lib/franc.js:240:27)
at detectAll (/home/dnaber/nodejs/node_modules/franc/lib/franc.js:313:12)
at detect (/home/dnaber/nodejs/node_modules/franc/lib/franc.js:325:12)
at Object.<anonymous> (/home/dnaber/crea/firefox-dict-switcher/nodejs/evaluation2.js:3:16)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Function.Module.runMain (module.js:497:10)
at startup (node.js:119:16)
wooorm commented 9 years ago

Weird, I just wondered about this today, if franc would fail on this. Thanks for reporting!