Skip to content

Commit

Permalink
add workaround for #17
Browse files Browse the repository at this point in the history
  • Loading branch information
silverwind committed Oct 30, 2023
1 parent 0ce9d7f commit c7993d9
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
3 changes: 2 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,8 @@ function mapNets(nets) {
}

export function merge(nets) {
nets = uniq((Array.isArray(nets) ? nets : [nets]).map(parse));
// sort to workaround https://github.com/silverwind/cidr-tools/issues/17
nets = uniq((Array.isArray(nets) ? nets : [nets]).sort(compare).map(parse));
const maps = mapNets(nets);

const merged = {4: [], 6: []};
Expand Down
3 changes: 3 additions & 0 deletions index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ test("merge", () => {
expect(merge(["0.0.1.0/24", "0.0.2.0/24", "0.0.3.0/24", "0.0.4.0/24"])).toEqual(["0.0.1.0/24", "0.0.2.0/23", "0.0.4.0/24"]);
expect(merge(["0.0.175.0/24", "0.0.176.0/21", "0.0.184.0/21", "0.0.192.0/24"])).toEqual(["0.0.175.0/24", "0.0.176.0/20", "0.0.192.0/24"]);
expect(merge(["0.0.176.0/21", "0.0.184.0/21", "0.0.192.0/24"])).toEqual(["0.0.176.0/20", "0.0.192.0/24"]);
expect(merge(["1:1:1:1::/128", "1:1:1:2::/128"])).toEqual(["1:1:1:1::/128", "1:1:1:2::/128"]);
expect(merge(["::2:0:0/128", "::1:0:0/128"])).toEqual(["::1:0:0/128", "::2:0:0/128"]);
expect(merge(["::2:0:0/128", "::1:0:0/128", "::2:0:1/128"])).toEqual(["::1:0:0/128", "::2:0:0/127"]);
});

test("exclude", () => {
Expand Down

0 comments on commit c7993d9

Please sign in to comment.