From f4f2e02a539859a25317307f2d1bb85ff4300bcc Mon Sep 17 00:00:00 2001 From: vershinin_so Date: Fri, 5 Jun 2020 17:40:45 +0300 Subject: [PATCH] add tag with space --- src/constants/issuer-tags-translations.ts | 2 +- src/constants/subject-tags-translations.ts | 2 +- src/helpers/_parseCertInfo.test.ts | 12 ++++++++++++ src/helpers/_parseCertInfo.ts | 4 ++-- 4 files changed, 16 insertions(+), 4 deletions(-) diff --git a/src/constants/issuer-tags-translations.ts b/src/constants/issuer-tags-translations.ts index 375c343..aa64417 100644 --- a/src/constants/issuer-tags-translations.ts +++ b/src/constants/issuer-tags-translations.ts @@ -12,7 +12,7 @@ export const ISSUER_TAGS_TRANSLATIONS: TagsTranslations[] = [ { possibleNames: ['ОГРН', 'OGRN'], translation: 'ОГРН' }, { possibleNames: ['ОГРНИП', 'OGRNIP'], translation: 'ОГРНИП' }, { possibleNames: ['СНИЛС', 'SNILS'], translation: 'СНИЛС' }, - { possibleNames: ['ИНН', 'INN'], translation: 'ИНН' }, + { possibleNames: ['ИНН', 'INN', 'ИНН организации'], translation: 'ИНН' }, { possibleNames: ['E'], translation: 'Email' }, { possibleNames: ['L'], translation: 'Город' }, ]; diff --git a/src/constants/subject-tags-translations.ts b/src/constants/subject-tags-translations.ts index 381ebda..e6b1003 100644 --- a/src/constants/subject-tags-translations.ts +++ b/src/constants/subject-tags-translations.ts @@ -14,7 +14,7 @@ export const SUBJECT_TAGS_TRANSLATIONS: TagsTranslations[] = [ { possibleNames: ['ОГРН', 'OGRN'], translation: 'ОГРН' }, { possibleNames: ['ОГРНИП', 'OGRNIP'], translation: 'ОГРНИП' }, { possibleNames: ['СНИЛС', 'SNILS'], translation: 'СНИЛС' }, - { possibleNames: ['ИНН', 'INN'], translation: 'ИНН' }, + { possibleNames: ['ИНН', 'INN', 'ИНН организации'], translation: 'ИНН' }, { possibleNames: ['E'], translation: 'Email' }, { possibleNames: ['L'], translation: 'Город' }, ]; diff --git a/src/helpers/_parseCertInfo.test.ts b/src/helpers/_parseCertInfo.test.ts index abc1412..adec6d6 100644 --- a/src/helpers/_parseCertInfo.test.ts +++ b/src/helpers/_parseCertInfo.test.ts @@ -19,6 +19,7 @@ describe('_parseCertInfo', () => { 'UNKNOWN=неизвестный тэг', 'E=email@example.ru', 'INN=007811514257', + 'ИНН организации=007811514257', 'OGRN=1127847087885', 'SNILS=11617693460', ].join(', '); @@ -99,6 +100,11 @@ describe('_parseCertInfo', () => { title: 'ИНН', isTranslated: true, }, + { + description: '007811514257', + title: 'ИНН', + isTranslated: true, + }, { description: '1127847087885', title: 'ОГРН', @@ -123,6 +129,7 @@ describe('_parseCertInfo', () => { 'S=78 Санкт-Петербург', 'C=RU', 'INN=007813317783', + 'ИНН организации=007813317783', 'OGRN=1057810150892', 'E=uc@sampokey.ru', ].join(', '); @@ -173,6 +180,11 @@ describe('_parseCertInfo', () => { title: 'ИНН', isTranslated: true, }, + { + description: '007813317783', + title: 'ИНН', + isTranslated: true, + }, { description: '1057810150892', title: 'ОГРН', diff --git a/src/helpers/_parseCertInfo.ts b/src/helpers/_parseCertInfo.ts index d362e8c..521a560 100644 --- a/src/helpers/_parseCertInfo.ts +++ b/src/helpers/_parseCertInfo.ts @@ -15,11 +15,11 @@ export interface TagTranslation { * @returns расшифрованная информация по отдельным тэгам */ export const _parseCertInfo = (tagsTranslations: TagsTranslations[], rawInfo: string): TagTranslation[] => { - const extractedEntities: string[] = rawInfo.match(/([а-яА-Яa-zA-Z0-9.]+)=(?:("[^"]+?")|(.+?))(?:,|$)/g); + const extractedEntities: string[] = rawInfo.match(/([а-яА-Яa-zA-Z0-9\s.]+)=(?:("[^"]+?")|(.+?))(?:,|$)/g); if (extractedEntities) { return extractedEntities.map((group) => { - const segmentsMatch = group.match(/^([а-яА-Яa-zA-Z0-9.]+)=(.+?),?$/); + const segmentsMatch = group.trim().match(/^([а-яА-Яa-zA-Z0-9\s.]+)=(.+?),?$/); let title = segmentsMatch?.[1]; // Вырезаем лишние кавычки const description = segmentsMatch?.[2]?.replace(/^"(.*)"/, '$1')?.replace(/"{2}/g, '"');