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');