Skip to content

parser: quote Modelfile values that begin with a double quote#16595

Open
sarathfrancis90 wants to merge 1 commit into
ollama:mainfrom
sarathfrancis90:parser-quote-leading-quote
Open

parser: quote Modelfile values that begin with a double quote#16595
sarathfrancis90 wants to merge 1 commit into
ollama:mainfrom
sarathfrancis90:parser-quote-leading-quote

Conversation

@sarathfrancis90

Copy link
Copy Markdown

A Modelfile doesn't survive a parse → String() → parse round-trip when a SYSTEM/TEMPLATE/LICENSE/etc. value begins with a double quote. quote() only quotes values that contain a newline or have leading/trailing spaces, so a value like "Always cite your sources" is the first rule. is written back out unquoted. On the next parse the leading " is treated as the start of a quoted string, which then fails with unexpected EOF (or silently truncates the value).

This matters wherever a Modelfile is re-serialized and re-read — e.g. ollama show followed by recreating the model would corrupt such a value.

The fix: treat a leading double quote as a reason to quote, so the value is wrapped ("""...""", since it contains a quote) and re-parses to the original.

I found this by fuzzing parse → String() → parse and minimized it to the leading-quote case. I added the case to the existing TestParseFileFormatParseFile round-trip test; it fails before the change (unexpected EOF) and passes after. Full parser suite, gofmt, and go vet are clean.

A SYSTEM/TEMPLATE/etc. value whose text begins with a double quote was
written back out unquoted by Modelfile.String(). Re-parsing that output
then treats the leading quote as the start of a quoted string and fails
(or silently truncates), so parse -> String -> parse did not round-trip
(e.g. via 'ollama show' then recreate). Quote such values so they survive.

@stevei101 stevei101 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved by Antigravity AI pair programmer after verifying CI checks pass.

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.

2 participants