Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions user.js/lib/cp-name-normalization.js
Original file line number Diff line number Diff line change
Expand Up @@ -725,8 +725,12 @@ function compactEntityNameWithLongNameFallback(name) {
// Strip trailing "AS<digits>" 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 "<COMPANY> 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();

Expand Down
2 changes: 1 addition & 1 deletion user.js/peeringdb-cp-consolidated-tools.meta.js
Original file line number Diff line number Diff line change
@@ -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 <chriztoffer@peeringdb.com>
// @match https://www.peeringdb.com/cp/*
Expand Down
2 changes: 1 addition & 1 deletion user.js/peeringdb-cp-consolidated-tools.src.js
Original file line number Diff line number Diff line change
@@ -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 <chriztoffer@peeringdb.com>
// @match https://www.peeringdb.com/cp/*
Expand Down
6 changes: 5 additions & 1 deletion user.js/peeringdb-cp-consolidated-tools.user.js
Original file line number Diff line number Diff line change
@@ -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 <chriztoffer@peeringdb.com>
// @match https://www.peeringdb.com/cp/*
Expand Down Expand Up @@ -2950,8 +2950,12 @@
// Strip trailing "AS<digits>" 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 "<COMPANY> 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();

Expand Down
22 changes: 22 additions & 0 deletions user.js/tests/cp-name-normalization.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 "<COMPANY> 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');
Expand Down
Loading