Skip to content

Commit

Permalink
Enforce leading zeroes in MAC addresses
Browse files Browse the repository at this point in the history
Fixes #3.
  • Loading branch information
pixelistik committed Apr 2, 2016
1 parent a2a9f84 commit 1bd449c
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
20 changes: 20 additions & 0 deletions spec/nodeListTransformSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,24 @@ describe("Wifi Analyzer alias list", function () {

assert.notInclude(result.join(), "undefined");
});

/**
* https://github.com/pixelistik/ff-alias-list-app/issues/3
*/
it("should keep leading zeroes in a mac", function () {
var result = nodeListTransform({
nodes: {
c423523487: {
nodeinfo: {
hostname: "host-one",
network: {
mac: "01:02:03:ee:01:01"
}
}
}
}
});
assert.include(result.join(), "03:04:04:ee:01:01");
assert.include(result.join(), "03:04:05:ee:01:01");
});
});
7 changes: 6 additions & 1 deletion www/js/nodeListTransform.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,17 @@
macParts[1] = (parseInt(macParts[1], 16) + 2).toString(16);
macParts[2] = (parseInt(macParts[2], 16) + offset).toString(16);

// Enforce leading zeroes
macParts = macParts.map(function (macPart) {
return ("0" + macPart).substr(macPart.length - 1)
});

return {
hostname: node.hostname,
mac: macParts.join(":")
};
}

var extendedMacList = [];

macList.forEach(function (node) {
Expand Down

0 comments on commit 1bd449c

Please sign in to comment.