Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure value is a String before calling toLowerCase() on it (Fixes #113) #114

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions lib/ip.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,11 @@ ip.isV4Format = function(ip) {
ip.isV6Format = function(ip) {
return ipv6Regex.test(ip);
};
function _resolveFamily(family) {
return typeof family === 'number' ? 'ipv' + family : family.toLowerCase();
}
function _normalizeFamily(family) {
return family ? family.toLowerCase() : 'ipv4';
return family ? _resolveFamily(family) : 'ipv4';
}

ip.fromPrefixLen = function(prefixlen, family) {
Expand Down Expand Up @@ -368,7 +371,7 @@ ip.address = function(name, family) {
//
if (name && name !== 'private' && name !== 'public') {
var res = interfaces[name].filter(function(details) {
var itemFamily = details.family.toLowerCase();
var itemFamily = _resolveFamily(details.family);
return itemFamily === family;
});
if (res.length === 0)
Expand All @@ -382,7 +385,7 @@ ip.address = function(name, family) {
// when this is called.
//
var addresses = interfaces[nic].filter(function (details) {
details.family = details.family.toLowerCase();
details.family = _resolveFamily(details.family);
if (details.family !== family || ip.isLoopback(details.address)) {
return false;
} else if (!name) {
Expand Down