From 6fdbf9dd9465484281fad14f06af93acf1627835 Mon Sep 17 00:00:00 2001 From: gorhill Date: Sat, 26 Sep 2015 11:51:06 -0400 Subject: [PATCH] this addresses #122 --- src/js/matrix.js | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/js/matrix.js b/src/js/matrix.js index e051cb3..5be8a65 100644 --- a/src/js/matrix.js +++ b/src/js/matrix.js @@ -26,6 +26,8 @@ µMatrix.Matrix = (function() { +'use strict'; + /******************************************************************************/ var µm = µMatrix; @@ -167,7 +169,7 @@ var toBroaderHostname = function(hostname) { return ''; } if ( isIPAddress(hostname) ) { - return '*'; + return toBroaderIPAddress(hostname); } var pos = hostname.indexOf('.'); if ( pos === -1 ) { @@ -176,6 +178,15 @@ var toBroaderHostname = function(hostname) { return hostname.slice(pos + 1); }; +var toBroaderIPAddress = function(ipaddress) { + // Can't broaden IPv6 (for now) + if ( ipaddress.charAt(0) === '[' ) { + return '*'; + } + var pos = ipaddress.lastIndexOf('.'); + return pos !== -1 ? ipaddress.slice(0, pos) : '*'; +}; + Matrix.toBroaderHostname = toBroaderHostname; /******************************************************************************/