fix(sidebar): keep a linked SQL file's other header lines when editing its metadata - #3084
Merged
Merged
Conversation
|
Preview deployment for your docs. Learn more about Mintlify Previews.
💡 Tip: Enable Automations to automatically generate PRs for you. |
datlechin
force-pushed
the
fix/linked-metadata-keeps-unknown-keys
branch
from
September 23, 2026 15:48
6dd738e to
d3da1e3
Compare
This branch was successfully deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Edit Metadata on a linked SQL file deleted every header line other than
@name,@keywordand@description. A file with-- @author: aliceand-- @reviewed: 2026-09-01lost both on the first save, and a leading-- @formatter:offwas deleted too. Found while investigating #2505.Measured on
mainwith-- @name: Monthly revenue\n-- @author: alice\n-- @reviewed: 2026-09-01\n-- @keyword: rev\nSELECT 1;\n: the save wrote-- @name: Monthly revenue\n-- @keyword: rev\n\nSELECT 1;\n. A CRLF file came back with an LF header over a CRLF body, and a description with a line break wrote its second line into the SQL.Root cause
SQLFrontmatter.parseWithBodycounts any leading-- @<key>: valueline as frontmatter and moves the body offset past it, but only readsname,keywordanddescription.LinkedSQLFavoriteWriter.writeMetadatakept the text after that offset, andrenderwrote back only those three keys, joined with\n. The parser consumed every other line in the block, and nothing wrote it back.Fix
SQLFrontmatter.split(_:)returns the header as lines, each with its raw text, its own terminator, its key and its value, plus the byte order mark and the untouched body.parse(_:)is built on it and reads the same metadata as before.SQLFrontmatter.Keynames the three keys the app owns, in canonical order.LinkedSQLFavoriteWriter.rewrite(_:with:)is a pure function that changes only the owned lines:-- @key: valueon the same line ending; a cleared one removes only its line; a duplicated owned key collapses to one line;\n;writeMetadatais unchanged.-- @key: valueline as part of the block. That no longer decides what survives a save, since every line the app does not own is copied through.docs/features/favorites.mdxnow says where the block ends and what Edit Metadata changes. It no longer claims the file keeps its encoding.FileTextLoader.loadstrips a byte order mark, so a UTF-8 file with a BOM loses it on save and a UTF-16 BE file is written back little-endian. That behaviour predates this change and is left for a separate fix.Tests
LinkedSQLFavoriteWriterTests: rename with foreign keys, byte-for-byte identity on unchanged metadata, canonical insertion, insertion before an existing keyword, clearing one key, clearing all keys,-- @formatter:off, CRLF preservation, CRLF for a created header, blank separator for a created header, multi-line description, duplicate owned keys, parse-back of the rewritten header, and awriteMetadataround trip through a temporary file on disk.writeMetadata, and compares the bytes on disk.SQLFrontmatterTests(5): raw text and terminators per header line (LF, CRLF, CR), block ending at a blank line, a last header line with no terminator, byte order mark, and owned keys read past foreign ones.main, 12 of the original 14 rewrite tests fail. The two that pass guard behaviour this change keeps on purpose: the blank separator and parse-back.