From 1c37ec7aee6bc571d5a22964bb859f5a295064d2 Mon Sep 17 00:00:00 2001 From: ansuz Date: Wed, 21 Aug 2019 12:24:12 +0200 Subject: [PATCH] prevent duplicated owners in metadata amendments --- lib/deduplicate.js | 11 +++++++++++ lib/metadata.js | 4 +++- 2 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 lib/deduplicate.js diff --git a/lib/deduplicate.js b/lib/deduplicate.js new file mode 100644 index 000000000..3ad62e6b0 --- /dev/null +++ b/lib/deduplicate.js @@ -0,0 +1,11 @@ +// remove duplicate elements in an array +module.exports = function (O) { + // make a copy of the original array + var A = O.slice(); + for (var i = 0; i < A.length; i++) { + for (var j = i + 1; j < A.length; j++) { + if (A[i] === A[j]) { A.splice(j--, 1); } + } + } + return A; +}; diff --git a/lib/metadata.js b/lib/metadata.js index 9c9fcbe78..185b3cf89 100644 --- a/lib/metadata.js +++ b/lib/metadata.js @@ -1,5 +1,7 @@ var Meta = module.exports; +var deduplicate = require("./deduplicate"); + /* Metadata fields: * channel @@ -64,7 +66,7 @@ commands.RESET_OWNERS = function (meta, args) { } // overwrite the existing owners with the new one - meta.owners = args; + meta.owners = deduplicate(args); }; commands.UPDATE_EXPIRATION = function () {