From 819a7bbe538ea64a4ed1dda59c56b76c66e87661 Mon Sep 17 00:00:00 2001 From: Nino Date: Thu, 30 Oct 2025 16:04:44 +0100 Subject: [PATCH] hotfix(catalog): correct regex pattern matching for Reihe line detection Centralized the Reihe prefix pattern into a shared constant to ensure consistent matching across LineTypePipe and ReiheRoutePipe. The pattern now correctly matches "Reihe:", "Reihe/Set:", and "Set/Reihe:" prefixes. Additionally enhanced the ReiheRoutePipe to strip trailing numbers from series names (e.g., "Harry Potter 1" -> "Harry Potter") to improve search query accuracy when navigating to article search results. Changes: - Created REIHE_PREFIX_PATTERN constant for shared regex pattern - Updated LineTypePipe to use centralized pattern (fixed capture group index) - Updated ReiheRoutePipe to use centralized pattern and strip trailing numbers Ref: #5421 --- .../article-details-text/line-type.pipe.ts | 5 ++-- .../article-details-text/reihe-route.pipe.ts | 25 +++++++++++++++---- .../article-details-text/reihe.constants.ts | 5 ++++ 3 files changed, 28 insertions(+), 7 deletions(-) create mode 100644 apps/isa-app/src/page/catalog/article-details/article-details-text/reihe.constants.ts diff --git a/apps/isa-app/src/page/catalog/article-details/article-details-text/line-type.pipe.ts b/apps/isa-app/src/page/catalog/article-details/article-details-text/line-type.pipe.ts index f232a104d..b250b0ff0 100644 --- a/apps/isa-app/src/page/catalog/article-details/article-details-text/line-type.pipe.ts +++ b/apps/isa-app/src/page/catalog/article-details/article-details-text/line-type.pipe.ts @@ -1,4 +1,5 @@ import { Pipe, PipeTransform } from '@angular/core'; +import { REIHE_PREFIX_PATTERN } from './reihe.constants'; @Pipe({ name: 'lineType', @@ -7,8 +8,8 @@ import { Pipe, PipeTransform } from '@angular/core'; }) export class LineTypePipe implements PipeTransform { transform(value: string, ...args: any[]): 'text' | 'reihe' { - const REIHE_REGEX = /^Reihe:\s*"(.+)\"$/g; - const reihe = REIHE_REGEX.exec(value)?.[1]; + const REIHE_REGEX = new RegExp(`^${REIHE_PREFIX_PATTERN}:\\s*"(.+)"$`, 'g'); + const reihe = REIHE_REGEX.exec(value)?.[2]; return reihe ? 'reihe' : 'text'; } } diff --git a/apps/isa-app/src/page/catalog/article-details/article-details-text/reihe-route.pipe.ts b/apps/isa-app/src/page/catalog/article-details/article-details-text/reihe-route.pipe.ts index c0d22c21a..b08876e4d 100644 --- a/apps/isa-app/src/page/catalog/article-details/article-details-text/reihe-route.pipe.ts +++ b/apps/isa-app/src/page/catalog/article-details/article-details-text/reihe-route.pipe.ts @@ -1,9 +1,15 @@ -import { ChangeDetectorRef, OnDestroy, Pipe, PipeTransform } from '@angular/core'; +import { + ChangeDetectorRef, + OnDestroy, + Pipe, + PipeTransform, +} from '@angular/core'; import { ApplicationService } from '@core/application'; import { ProductCatalogNavigationService } from '@shared/services/navigation'; import { isEqual } from 'lodash'; import { Subscription, combineLatest, BehaviorSubject } from 'rxjs'; import { distinctUntilChanged } from 'rxjs/operators'; +import { REIHE_PREFIX_PATTERN } from './reihe.constants'; @Pipe({ name: 'reiheRoute', @@ -22,10 +28,13 @@ export class ReiheRoutePipe implements PipeTransform, OnDestroy { private application: ApplicationService, private cdr: ChangeDetectorRef, ) { - this.subscription = combineLatest([this.application.activatedProcessId$, this.value$]) + this.subscription = combineLatest([ + this.application.activatedProcessId$, + this.value$, + ]) .pipe(distinctUntilChanged(isEqual)) .subscribe(([processId, value]) => { - const REIHE_REGEX = /[";]|Reihe:/g; // Entferne jedes Semikolon, Anführungszeichen und den String Reihe: + const REIHE_REGEX = new RegExp(`[";]|${REIHE_PREFIX_PATTERN}:`, 'g'); // Entferne jedes Semikolon, Anführungszeichen und den String Reihe:/Reihe/Set:/Set/Reihe: const reihe = value?.replace(REIHE_REGEX, '')?.trim(); if (!reihe) { @@ -33,9 +42,15 @@ export class ReiheRoutePipe implements PipeTransform, OnDestroy { return; } - const main_qs = reihe.split('/')[0]; + // Entferne Zahlen am Ende, die mit Leerzeichen, Komma, Slash oder Semikolon getrennt sind + // Beispiele: "Harry Potter 1" -> "Harry Potter", "Harry Potter,1" -> "Harry Potter", "Harry Potter/2" -> "Harry Potter" + const main_qs = reihe + .split('/')[0] + .replace(/[\s,;]+\d+$/g, '') + .trim(); - const path = this.navigation.getArticleSearchResultsPath(processId).path; + const path = + this.navigation.getArticleSearchResultsPath(processId).path; this.result = { path, diff --git a/apps/isa-app/src/page/catalog/article-details/article-details-text/reihe.constants.ts b/apps/isa-app/src/page/catalog/article-details/article-details-text/reihe.constants.ts new file mode 100644 index 000000000..61c3941ee --- /dev/null +++ b/apps/isa-app/src/page/catalog/article-details/article-details-text/reihe.constants.ts @@ -0,0 +1,5 @@ +/** + * Shared regex pattern for matching Reihe line prefixes. + * Matches: "Reihe:", "Reihe/Set:", or "Set/Reihe:" + */ +export const REIHE_PREFIX_PATTERN = '(Reihe|Reihe\\/Set|Set\\/Reihe)';