From f16446950c2634154a1796ff4cdaf6ad7f037d59 Mon Sep 17 00:00:00 2001 From: Chris Roberts Date: Mon, 23 Jun 2025 14:19:07 -0500 Subject: [PATCH] Correctly build URLs to file paths containing spaces Previously, such paths would have their spaces replaced with `/`s, breaking external links to the file. Fixes #249 --- CHANGELOG.md | 5 +++++ packages/web/src/features/search/searchApi.ts | 5 +++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 57143256..a121f0de 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,11 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [Unreleased] + +### Fixed +- Fixed issue with external source code links being broken for paths with spaces. [#364](https://github.com/sourcebot-dev/sourcebot/pull/364) + ## [4.5.0] - 2025-06-21 ### Added diff --git a/packages/web/src/features/search/searchApi.ts b/packages/web/src/features/search/searchApi.ts index e03a4d31..71aa6da5 100644 --- a/packages/web/src/features/search/searchApi.ts +++ b/packages/web/src/features/search/searchApi.ts @@ -106,13 +106,14 @@ const getFileWebUrl = (template: string, branch: string, fileName: string): stri const url = template.substring("{{URLJoinPath ".length, template.indexOf("}}")) - .replace(".Version", branch) - .replace(".Path", fileName) .split(" ") .map((part) => { // remove wrapping quotes if (part.startsWith("\"")) part = part.substring(1); if (part.endsWith("\"")) part = part.substring(0, part.length - 1); + // Replace variable references + if (part == ".Version") part = branch; + if (part == ".Path") part = fileName; return part; }) .join("/");