From 94e51f26f91e9998522c7faa75728a16a2bb592a Mon Sep 17 00:00:00 2001 From: ch <1938389+netravnen@users.noreply.github.com> Date: Wed, 25 Nov 2026 22:19:45 +0100 Subject: [PATCH] fix(cp): drop a dangling trailing dash before deriving Long Name registro.br cuts owner names at 50 characters, so a name like " SERVICOS DE COMUNICACAO MULTIMIDIA - ME" arrives as "... MULTIMIDIA -" (net 25126 / org 45040, AS266063). The short Name was already clean, but compactEntityNameWithLongNameFallback kept the dash in the full name and wrote "... MULTIMIDIA -" to Long Name. Changes: - compactEntityNameWithLongNameFallback drops a trailing spaced "-", en dash, em dash or "/" (also after a comma) along with the dangling "," and ";" it already drops. An unspaced "Foo-" and a real suffix after the dash ("... - ME") are unchanged. - Bump CP to 2.0.237. Security: - N/A Testing: - New tests on placeholder data for the cut-off shape, each dash form, and the unchanged suffix and unspaced cases. - build_userscripts.py --check and node --check pass. - node --test in user.js: 641 tests, 640 pass, 1 skipped, 0 fail. - The 9 scratch name-normalization harnesses give identical output to master. Backwards Compatibility: - Only names ending in a spaced dangling dash or slash change: their Long Name loses the separator or is no longer written. Assisted-by: Claude:claude-opus-5-5 --- user.js/lib/cp-name-normalization.js | 4 ++++ .../peeringdb-cp-consolidated-tools.meta.js | 2 +- .../peeringdb-cp-consolidated-tools.src.js | 2 +- .../peeringdb-cp-consolidated-tools.user.js | 6 ++++- user.js/tests/cp-name-normalization.test.js | 22 +++++++++++++++++++ 5 files changed, 33 insertions(+), 3 deletions(-) diff --git a/user.js/lib/cp-name-normalization.js b/user.js/lib/cp-name-normalization.js index 36b5387..92de534 100644 --- a/user.js/lib/cp-name-normalization.js +++ b/user.js/lib/cp-name-normalization.js @@ -725,8 +725,12 @@ function compactEntityNameWithLongNameFallback(name) { // Strip trailing "AS" patterns (e.g., "Cogeco Connexion Inc. AS27168" -> "Cogeco Connexion Inc.") // Then drop separators left dangling at the end, e.g. "MaVi-ST, AS218414" -> "MaVi-ST," // -> "MaVi-ST", so Long Name never ends in "," or ";". Periods are kept ("Inc."). + // A spaced dash or slash left dangling is dropped too: registro.br cuts owner names + // at 50 characters, so " SERVICOS DE COMUNICACAO MULTIMIDIA - ME" arrives + // as "... MULTIMIDIA -" (net 25126 / org 45040, AS266063). "Foo-" keeps its dash. const withoutAsns = fullName .replace(/\s+AS\s*\d+\s*$/i, "") + .replace(/(?:[\s,;]*\s[-\u2013\u2014/]+)+\s*$/, "") .replace(/[\s,;]+$/, "") .trim(); diff --git a/user.js/peeringdb-cp-consolidated-tools.meta.js b/user.js/peeringdb-cp-consolidated-tools.meta.js index 11de94d..c3995a0 100644 --- a/user.js/peeringdb-cp-consolidated-tools.meta.js +++ b/user.js/peeringdb-cp-consolidated-tools.meta.js @@ -1,7 +1,7 @@ // ==UserScript== // @name PeeringDB CP - Consolidated Tools // @namespace https://www.peeringdb.com/cp/ -// @version 2.0.236 +// @version 2.0.237 // @description Consolidated CP userscript with strict route-isolated modules for facility/network/user/entity workflows // @author // @match https://www.peeringdb.com/cp/* diff --git a/user.js/peeringdb-cp-consolidated-tools.src.js b/user.js/peeringdb-cp-consolidated-tools.src.js index a9e6304..d851f32 100644 --- a/user.js/peeringdb-cp-consolidated-tools.src.js +++ b/user.js/peeringdb-cp-consolidated-tools.src.js @@ -1,7 +1,7 @@ // ==UserScript== // @name PeeringDB CP - Consolidated Tools // @namespace https://www.peeringdb.com/cp/ -// @version 2.0.236 +// @version 2.0.237 // @description Consolidated CP userscript with strict route-isolated modules for facility/network/user/entity workflows // @author // @match https://www.peeringdb.com/cp/* diff --git a/user.js/peeringdb-cp-consolidated-tools.user.js b/user.js/peeringdb-cp-consolidated-tools.user.js index 443792b..cc2a324 100644 --- a/user.js/peeringdb-cp-consolidated-tools.user.js +++ b/user.js/peeringdb-cp-consolidated-tools.user.js @@ -1,7 +1,7 @@ // ==UserScript== // @name PeeringDB CP - Consolidated Tools // @namespace https://www.peeringdb.com/cp/ -// @version 2.0.236 +// @version 2.0.237 // @description Consolidated CP userscript with strict route-isolated modules for facility/network/user/entity workflows // @author // @match https://www.peeringdb.com/cp/* @@ -2950,8 +2950,12 @@ // Strip trailing "AS" patterns (e.g., "Cogeco Connexion Inc. AS27168" -> "Cogeco Connexion Inc.") // Then drop separators left dangling at the end, e.g. "MaVi-ST, AS218414" -> "MaVi-ST," // -> "MaVi-ST", so Long Name never ends in "," or ";". Periods are kept ("Inc."). + // A spaced dash or slash left dangling is dropped too: registro.br cuts owner names + // at 50 characters, so " SERVICOS DE COMUNICACAO MULTIMIDIA - ME" arrives + // as "... MULTIMIDIA -" (net 25126 / org 45040, AS266063). "Foo-" keeps its dash. const withoutAsns = fullName .replace(/\s+AS\s*\d+\s*$/i, "") + .replace(/(?:[\s,;]*\s[-\u2013\u2014/]+)+\s*$/, "") .replace(/[\s,;]+$/, "") .trim(); diff --git a/user.js/tests/cp-name-normalization.test.js b/user.js/tests/cp-name-normalization.test.js index 232dbc0..f754195 100644 --- a/user.js/tests/cp-name-normalization.test.js +++ b/user.js/tests/cp-name-normalization.test.js @@ -605,6 +605,28 @@ test('stripTurkishSectorDescriptorTail', async (t) => { }); }); +test('compactEntityNameWithLongNameFallback drops a dangling trailing dash', async (t) => { + // Shape of net 25126 / org 45040 (AS266063): registro.br cut the owner name at 50 + // characters, after " SERVICOS DE COMUNICACAO MULTIMIDIA -". + await t.test('no Long Name from a name that only adds " -"', () => { + assert.deepEqual( + lib.compactEntityNameWithLongNameFallback('EXAMPLE SERVICOS DE COMUNICACAO MULTIMIDIA -'), + { shortName: 'EXAMPLE SERVICOS DE COMUNICACAO MULTIMIDIA', longName: '' }, + ); + }); + + await t.test('en dash, em dash, slash and a comma before the dash', () => { + for (const name of ['Example Net \u2013', 'Example Net \u2014', 'Example Net /', 'Example Net, -']) { + assert.deepEqual(lib.compactEntityNameWithLongNameFallback(name), { shortName: 'Example Net', longName: '' }, name); + } + }); + + await t.test('keeps a real suffix after the dash and an unspaced dash', () => { + assert.equal(lib.compactEntityNameWithLongNameFallback('Example Multimidia - ME').longName, 'Example Multimidia - ME'); + assert.equal(lib.compactEntityNameWithLongNameFallback('Example-').shortName, 'Example'); + }); +}); + test('getDeterministicNetworkFallbackName', () => { assert.equal(lib.getDeterministicNetworkFallbackName(12345, 42, ' #42'), 'Network 42 #42'); assert.equal(lib.getDeterministicNetworkFallbackName(null, 7), 'Network 7');