From b0e12bc12bc46ffee7eb35fb36c85bbadd2a7d84 Mon Sep 17 00:00:00 2001 From: Harry Dobrev Date: Tue, 6 Oct 2026 02:20:13 +0300 Subject: [PATCH] Match abroad section ids with a non-zero 6th digit. CIK's 2026 abroad ids use 0, 1 or 2 in the 6th position (320012001, 320291132). SECTION_SEGMENT_BREAKDOWN only allowed 0 there, so GET /sections/:id, /results/:segment.json and the violations feed failed for 512 of the 613 abroad sections. --- src/sections/sections-pattern.spec.ts | 28 +++++++++++++++++++++++++++ src/sections/sections-pattern.ts | 2 +- 2 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 src/sections/sections-pattern.spec.ts diff --git a/src/sections/sections-pattern.spec.ts b/src/sections/sections-pattern.spec.ts new file mode 100644 index 0000000..86382f9 --- /dev/null +++ b/src/sections/sections-pattern.spec.ts @@ -0,0 +1,28 @@ +import { SECTION_SEGMENT_BREAKDOWN } from './sections-pattern' + +describe('SECTION_SEGMENT_BREAKDOWN', () => { + it.each(['320010003', '320012001', '320291132'])( + 'matches the full abroad section id %s', + (id) => { + const groups = SECTION_SEGMENT_BREAKDOWN.exec(id)?.groups + expect(groups?.abroadRegionCode).toBe('32') + expect(groups?.countryCode).toBe(id.slice(2, 5)) + expect(groups?.sectionCodeAbroad).toBe(id.slice(6)) + }, + ) + + it('still matches abroad region and country segments', () => { + expect(SECTION_SEGMENT_BREAKDOWN.exec('32')?.groups?.abroadRegionCode).toBe( + '32', + ) + expect(SECTION_SEGMENT_BREAKDOWN.exec('32001')?.groups?.countryCode).toBe( + '001', + ) + }) + + it('still matches domestic segments', () => { + const groups = SECTION_SEGMENT_BREAKDOWN.exec('010100001')?.groups + expect(groups?.electionRegionCode).toBe('01') + expect(groups?.sectionCodeDomestic).toBe('001') + }) +}) diff --git a/src/sections/sections-pattern.ts b/src/sections/sections-pattern.ts index fee7891..383b395 100644 --- a/src/sections/sections-pattern.ts +++ b/src/sections/sections-pattern.ts @@ -1,2 +1,2 @@ export const SECTION_SEGMENT_BREAKDOWN = - /^(?0[1-9]|[12][0-9]|3[01])(?:(?[0-9]{2})(?:(?[0-9]{2})(?[0-9]{3})?)?)?$|^(?32)(?:(?[0-9]{3})(?:0(?[0-9]{3})?)?)?$/ + /^(?0[1-9]|[12][0-9]|3[01])(?:(?[0-9]{2})(?:(?[0-9]{2})(?[0-9]{3})?)?)?$|^(?32)(?:(?[0-9]{3})(?:[0-9](?[0-9]{3})?)?)?$/