Skip to content

Commit

Permalink
CIDR array response reversed to properly deliminated string
Browse files Browse the repository at this point in the history
  • Loading branch information
fredthomsen authored and whitequark committed Jun 10, 2018
1 parent 8e69afe commit 34149be
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 7 deletions.
2 changes: 1 addition & 1 deletion ipaddr.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 16 additions & 4 deletions lib/ipaddr.js
Original file line number Diff line number Diff line change
Expand Up @@ -492,11 +492,17 @@
};

ipaddr.IPv4.parseCIDR = function(string) {
var maskLength, match;
var maskLength, match, parsed;
if (match = string.match(/^(.+)\/(\d+)$/)) {
maskLength = parseInt(match[2]);
if (maskLength >= 0 && maskLength <= 32) {
return [this.parse(match[1]), maskLength];
parsed = [this.parse(match[1]), maskLength];
Object.defineProperty(parsed, 'toString', {
value: function() {
return this.join('/');
}
});
return parsed;
}
}
throw new Error("ipaddr: string is not formatted like an IPv4 CIDR range");
Expand Down Expand Up @@ -560,11 +566,17 @@
};

ipaddr.IPv6.parseCIDR = function(string) {
var maskLength, match;
var maskLength, match, parsed;
if (match = string.match(/^(.+)\/(\d+)$/)) {
maskLength = parseInt(match[2]);
if (maskLength >= 0 && maskLength <= 128) {
return [this.parse(match[1]), maskLength];
parsed = [this.parse(match[1]), maskLength];
Object.defineProperty(parsed, 'toString', {
value: function() {
return this.join('/');
}
});
return parsed;
}
}
throw new Error("ipaddr: string is not formatted like an IPv6 CIDR range");
Expand Down
Loading

0 comments on commit 34149be

Please sign in to comment.