Skip to content

fix(frontend): collapse duplicate URL path slashes before React Router#1596

Open
kaligrafy wants to merge 1 commit into
chairemobilite:mainfrom
kaligrafy:fix/double-slash-pathname-normalization
Open

fix(frontend): collapse duplicate URL path slashes before React Router#1596
kaligrafy wants to merge 1 commit into
chairemobilite:mainfrom
kaligrafy:fix/double-slash-pathname-normalization

Conversation

@kaligrafy
Copy link
Copy Markdown
Contributor

Add replaceBrowserPathnameIfNeeded on admin and participant entrypoints, with a small pathname helper and Jest coverage. Add a Playwright spec in demo_survey for //home and related cases.

closes #2

@kaligrafy kaligrafy requested a review from tahini May 14, 2026 20:49
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 14, 2026

Warning

Rate limit exceeded

@kaligrafy has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 54 minutes and 52 seconds before requesting another review.

You’ve run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: c981d67c-90dd-4f7e-882c-c870f95b5235

📥 Commits

Reviewing files that changed from the base of the PR and between ea00754 and 5dff027.

📒 Files selected for processing (5)
  • example/demo_survey/tests/test-pathname-double-slash.UI.spec.ts
  • packages/evolution-frontend/src/apps/admin/index.tsx
  • packages/evolution-frontend/src/apps/participant/index.tsx
  • packages/evolution-frontend/src/utils/__tests__/normalizeBrowserLocationPathname.test.ts
  • packages/evolution-frontend/src/utils/normalizeBrowserLocationPathname.ts
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@tahini tahini left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Juste une question

Comment thread packages/evolution-frontend/src/apps/admin/index.tsx
Add replaceBrowserPathnameIfNeeded on admin and participant entrypoints,
with a small pathname helper and Jest coverage. Add a Playwright spec in
demo_survey for //home and related cases.

closes chairemobilite#2
@kaligrafy kaligrafy force-pushed the fix/double-slash-pathname-normalization branch from fee19d6 to 5dff027 Compare May 19, 2026 14:18
@kaligrafy kaligrafy requested a review from tahini May 19, 2026 14:18
* @param pathname - `window.location.pathname` (may include duplicate slashes)
* @returns Canonical pathname starting with `/` when non-empty
*/
export const collapseConsecutiveSlashesInPathname = (pathname: string): string => {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cette fonction a-t-elle vraiment besoin d'être exportée? Si elle n'est utilisée que dans ce fichier, éviter de l'exporter, sinon ça veut dire maintenant, ce n,est plus un détail d'implémentation, etc. etc.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, mais alors l'enjeu sera pour les tests:
mocker window.location en jsdom est très fragile et plus complexe que la fonction testée. Ajouter un JSDoc @internal ou un commentaire "Exported solely for unit testing — not part of the public surface" ferai-t-il l'affaire?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot me dit que c'est possible de faire ça sans mocker window.location, juste en faisant window.history.pushState({}, '', '/my/path?x=1#frag');. Est-ce que ça fonctionnerait?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

3/5 cas passent, 2 échouent. jsdom rejette pushState('//foo') avec SecurityError: pushState() cannot update history to the URL http://interviews/byCode/ABC123 parce que le parser URL interprète //host comme une autorité (host interviews) → origine différente → rejet.

Concrètement :

/foo//bar (slashs au milieu) : ✓ pushState accepte, origine inchangée
//foo, ///foo (préfixe) : ✗ jsdom les voit comme une nav cross-origin
Or le bug en prod est précisément le cas du préfixe (l'utilisateur tape //interviews/... dans la barre d'adresse, le navigateur l'envoie tel quel et React Router ne matche pas). Donc Copilot a raison sur le mécanisme, mais jsdom ne nous laisse pas reproduire le cas qu'on veut tester.

@kaligrafy kaligrafy requested a review from tahini May 20, 2026 15:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

evolution: URLs with // in it are not equivalent to /

2 participants