-
Notifications
You must be signed in to change notification settings - Fork 6
Open
Description
exports.detectOne = function (text) {
var langs = exports.detect(text);
return langs.length > 0 ? langs[0].lang : null;
};
Above is the implementation of the detectOne function from index.js. If the detect function failed to detect the language, it will return null. However, the detectOne function assumes that this will never happen. It tries to get the length property of the output from the detect function without checking whether it is null first. I recommend fixing this by using the code below instead:
exports.detectOne = function (text) {
var langs = exports.detect(text);
if (langs === null) return null;
return langs.length > 0 ? langs[0].lang : null;
};
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels