fix(web): Fix error when navigating to paths with percent symbols (#485)

* fix

* changelog
This commit is contained in:
Brendan Kellam 2025-09-01 11:45:05 -04:00 committed by GitHub
parent 2241217b0b
commit d4cb532e40
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 23 additions and 2 deletions

View file

@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Fixed ### Fixed
- Remove setting `remote.origin.url` for remote git repositories. [#483](https://github.com/sourcebot-dev/sourcebot/pull/483) - Remove setting `remote.origin.url` for remote git repositories. [#483](https://github.com/sourcebot-dev/sourcebot/pull/483)
- Fix error when navigating to paths with percentage symbols. [#485](https://github.com/sourcebot-dev/sourcebot/pull/485)
### Changed ### Changed
- Updated NextJS to version 15. [#477](https://github.com/sourcebot-dev/sourcebot/pull/477) - Updated NextJS to version 15. [#477](https://github.com/sourcebot-dev/sourcebot/pull/477)

View file

@ -19,7 +19,7 @@ export default async function BrowsePage(props: BrowsePageProps) {
domain domain
} = params; } = params;
const rawPath = decodeURIComponent(_rawPath.join('/')); const rawPath = _rawPath.join('/');
const { repoName, revisionName, path, pathType } = getBrowseParamsFromPathParam(rawPath); const { repoName, revisionName, path, pathType } = getBrowseParamsFromPathParam(rawPath);
return ( return (

View file

@ -98,6 +98,26 @@ describe('getBrowseParamsFromPathParam', () => {
pathType: 'blob', pathType: 'blob',
}); });
}); });
it('should decode paths with percent symbols in path', () => {
const result = getBrowseParamsFromPathParam('github.com/sourcebot-dev/zoekt@HEAD/-/blob/%25hello%25%2Fworld.c');
expect(result).toEqual({
repoName: 'github.com/sourcebot-dev/zoekt',
revisionName: 'HEAD',
path: '%hello%/world.c',
pathType: 'blob',
});
});
it('should decode paths with @ symbol encoded', () => {
const result = getBrowseParamsFromPathParam('github.com/sourcebot-dev/zoekt%40HEAD/-/blob/file.txt');
expect(result).toEqual({
repoName: 'github.com/sourcebot-dev/zoekt',
revisionName: 'HEAD',
path: 'file.txt',
pathType: 'blob',
});
})
}); });
describe('different revision formats', () => { describe('different revision formats', () => {

View file

@ -5,7 +5,7 @@ export const getBrowseParamsFromPathParam = (pathParam: string) => {
throw new Error(`Invalid browse pathname: "${pathParam}" - expected to contain "/-/(tree|blob)/" pattern`); throw new Error(`Invalid browse pathname: "${pathParam}" - expected to contain "/-/(tree|blob)/" pattern`);
} }
const repoAndRevisionPart = pathParam.substring(0, sentinelIndex); const repoAndRevisionPart = decodeURIComponent(pathParam.substring(0, sentinelIndex));
const lastAtIndex = repoAndRevisionPart.lastIndexOf('@'); const lastAtIndex = repoAndRevisionPart.lastIndexOf('@');
const repoName = lastAtIndex === -1 ? repoAndRevisionPart : repoAndRevisionPart.substring(0, lastAtIndex); const repoName = lastAtIndex === -1 ? repoAndRevisionPart : repoAndRevisionPart.substring(0, lastAtIndex);