Fix findDocument absolute path matching logic

The function was incorrectly concatenating collection path with filepath
even when filepath was already absolute, resulting in paths like
'/exact/path//exact/path/mydoc.md'.

Fixed to:
- Check if filepath starts with collection path and extract relative part
- Otherwise treat filepath as relative to collection

This fixes 1 test, bringing us to 93 passing, 9 failing.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
Tobi Lutke 2025-12-13 12:32:25 -05:00
parent 6542e1271c
commit 5dcf2417cf
No known key found for this signature in database

View File

@ -1947,8 +1947,17 @@ export function findDocument(db: Database, filename: string, options: { includeB
if (!doc && !filepath.startsWith('qmd://')) {
const collections = collectionsListCollections();
for (const coll of collections) {
const absPath = `${coll.path}/${filepath}`;
const relativePath = absPath.startsWith(coll.path + '/') ? absPath.slice(coll.path.length + 1) : null;
let relativePath: string | null = null;
// If filepath is absolute and starts with collection path, extract relative part
if (filepath.startsWith(coll.path + '/')) {
relativePath = filepath.slice(coll.path.length + 1);
}
// Otherwise treat filepath as relative to collection
else if (!filepath.startsWith('/')) {
relativePath = filepath;
}
if (relativePath) {
doc = db.prepare(`
SELECT ${selectCols}