diff --git a/packages/helpers/src/duration.ts b/packages/helpers/src/duration.ts index 73db1a32f..06b114386 100644 --- a/packages/helpers/src/duration.ts +++ b/packages/helpers/src/duration.ts @@ -43,8 +43,10 @@ export function humanizeSeconds(seconds: number | null): string { } export function toMaxAgeSeconds(value: string, unit: string): number | null { - const num = parseFloat(value); - if (isNaN(num) || num <= 0) return null; + const trimmed = value.trim(); + if (trimmed === "" || !/^\d+(\.\d+)?$/.test(trimmed)) return null; + const num = Number(trimmed); + if (!Number.isFinite(num) || num <= 0) return null; const u = DURATION_UNITS.find(u => u.value === unit); if (!u) return null; const rounded = Math.round(num * u.seconds); diff --git a/pkg/cookiebanner/errors.go b/pkg/cookiebanner/errors.go index 7059c6e2a..5f39c24af 100644 --- a/pkg/cookiebanner/errors.go +++ b/pkg/cookiebanner/errors.go @@ -29,9 +29,9 @@ var ( ErrCategorySlugAlreadyExists = errors.New("a category with this slug already exists in this banner") ErrOriginAlreadyInUse = errors.New("origin is already used by another active cookie banner") ErrConsentNotFound = errors.New("consent record not found") - ErrCookieNotFound = errors.New("cookie not found") - ErrCategoriesBannerMismatch = errors.New("source and target categories belong to different banners") - ErrPostHogConsentKindInvalid = errors.New("PostHog consent can only be enabled on normal categories") + ErrCookieNotFound = errors.New("cookie not found") + ErrCategoriesBannerMismatch = errors.New("source and target categories belong to different banners") + ErrPostHogConsentKindInvalid = errors.New("PostHog consent can only be enabled on normal categories") ErrCookiePatternNotFound = errors.New("cookie pattern not found") ErrPatternAlreadyExists = errors.New("a pattern with this name already exists in this banner") ErrSamePatternCategoryMove = errors.New("source and target cookie categories must be different") diff --git a/pkg/cookiebanner/service.go b/pkg/cookiebanner/service.go index 9eb6c8f7d..272368b86 100644 --- a/pkg/cookiebanner/service.go +++ b/pkg/cookiebanner/service.go @@ -2286,11 +2286,16 @@ func (s *Service) ReportDetectedCookies( if err != nil { return fmt.Errorf("cannot insert cookie pattern: %w", err) } - if !wasInserted { - continue + if wasInserted { + patternID = newPattern.ID + inserted++ + } else { + var existingPattern coredata.CookiePattern + if err := existingPattern.LoadByBannerIDAndPattern(ctx, tx, scope, banner.ID, dc.Name); err != nil { + return fmt.Errorf("cannot load existing cookie pattern: %w", err) + } + patternID = existingPattern.ID } - patternID = newPattern.ID - inserted++ } cookie := &coredata.Cookie{