equinor / equinor/fusion-framework

fix(dev-portal): potential unintended string replacement in context path generation

Open
#3,475 0 comments 0 reactions 1 assignee Claimed by @asbjornhaland View on GitHub
✨ improvement 🏗️ framework
Dominant language
TypeScript
Stars
10
Forks
10
Avg merge
19h 40m
Merged PRs (30d)
150

Description

This issue addresses a technical concern raised during PR #3471 review regarding the string replacement logic in the `generatePathname` function.

**Concern:**
The fallback logic `currentPathname.replace(pathContextId, item.id)` could potentially replace unintended substrings if `pathContextId` appears multiple times in the pathname or as part of other path segments.

**Current Implementation:**
```typescript
const pathname =
context?.generatePathFromContext?.(item, currentPathname) ??
currentPathname.replace(pathContextId, item.id);
```

**Potential Issue:**
If a pathname contains the `pathContextId` as a substring in other parts of the path (not just the context segment), this could lead to incorrect URL generation.

**Suggested Solutions:**
1. Implement segment-by-segment path replacement
2. Use more robust path parsing logic
3. Add validation to ensure replacement only affects the intended context segment

**Related PR:** https://github.com/equinor/fusion-framework/pull/3471

**Priority:** Medium - Should be addressed before the next major version to prevent potential routing issues.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.