Skip to content

Fix URL templates with text after the URLJoinPath block - #59

Open
mateusz-kolecki wants to merge 1 commit into
isker:masterfrom
mateusz-kolecki:url-template-suffix
Open

mateusz-kolecki wants to merge 1 commit into
isker:masterfrom
mateusz-kolecki:url-template-suffix

Conversation

@mateusz-kolecki

Copy link
Copy Markdown

Symptom

With a Zoekt index that contains repositories mirrored from Bitbucket Server, every search whose results include a file from one of those repositories fails:

zoekt call failed: SyntaxError: Unexpected token '.', ".Path}}?at"... is not valid JSON

Reproduced with neogrok v1.2.6 and Zoekt built from b55ce727df8cfbed76b8a1420445fd0cf93f3256 against Bitbucket Server 9.6.2.

Cause

Zoekt's Bitbucket Server file URL template puts the version in a query string after the URLJoinPath block:

{{URLJoinPath "https://host/projects/P/repos/r/browse" .Path}}?at={{.Version}}

urlJoinPathTemplate in src/lib/url-templates.ts anchors the closing }} to the end of the string, so the lazy args group runs all the way to the final }}. The last whitespace-split token is then .Path}}?at={{.Version, which is neither .Version nor .Path, so it is handed to JSON.parse as if it were a quoted string.

Fix

  • Capture whatever follows the URLJoinPath block in a suffix group.
  • Evaluate {{.Version}} and {{.Path}} inside the suffix with encodeURIComponent, since there they are single URL components (query values) rather than path segments.
  • Append the evaluated suffix in both evaluateFileUrlTemplate and evaluateCommitUrlTemplate. Templates without a suffix behave exactly as before.
  • Add a test with the Bitbucket Server template, including a path with a space and a refs/heads/... version.
  • Add a patch changeset.

yarn run lint and yarn run test pass locally. With this change the failing search renders Bitbucket Server links such as .../browse/Dockerfile?at=<sha> correctly.

🤖 Generated with Claude Code

Zoekt's Bitbucket Server file template is

  {{URLJoinPath "<repo-url>/browse" .Path}}?at={{.Version}}

The regex that recognizes URLJoinPath templates anchored the closing }}
to the end of the string, so the lazy args group ran up to the final }}
and the token `.Path}}?at={{.Version` reached JSON.parse. Every search
whose results included a file from a Bitbucket Server repository then
failed with "zoekt call failed: SyntaxError: Unexpected token '.'".

Capture whatever follows the URLJoinPath block as a suffix, evaluate
{{.Version}} and {{.Path}} in it as single URL components, and append it
to the joined path for both file and commit templates.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
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.

1 participant