[PR #14126] parser: allow multiple spaces after PARAMETER and MESSAGE keywords #19798

Open
opened 2026-04-16 07:16:40 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/ollama/ollama/pull/14126
Author: @4RH1T3CT0R7
Created: 2/6/2026
Status: 🔄 Open

Base: mainHead: fix/modelfile-whitespace-parsing


📝 Commits (1)

  • 2ed36e5 parser: allow multiple spaces after PARAMETER and MESSAGE keywords

📊 Changes

2 files changed (+43 additions, -7 deletions)

View changed files

📝 parser/parser.go (+15 -7)
📝 parser/parser_test.go (+28 -0)

📄 Description

Summary

Fixes #13359

The Modelfile parser fails when there are multiple spaces between PARAMETER/MESSAGE keywords and their arguments:

  • PARAMETER temperature 0.5 works
  • PARAMETER temperature 0.5 fails with "unknown parameter ''"
  • MESSAGE user hello fails with "message role must be one of..."

Root cause: In ParseFile(), when stateParameter or stateMessage transitions on a space character, the accumulated buffer is used as cmd.Name or role. If only spaces have been read since entering the state (buffer is empty), the transition fires prematurely with an empty string.

Fix: Check if the buffer is empty before transitioning out of stateParameter/stateMessage. If empty, stay in the current state to skip leading whitespace. This is a minimal change (6 lines of logic) that only affects these two states — it does not touch SYSTEM, FROM, ADAPTER, or any triple-quote handling.

Test plan

  • Added test cases to TestParseFileTrimSpace with multiple spaces after PARAMETER
  • Added test cases to TestParseFileMessages with multiple spaces after MESSAGE
  • All existing parser tests pass (go test ./parser/ -v — 60+ tests)

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/ollama/ollama/pull/14126 **Author:** [@4RH1T3CT0R7](https://github.com/4RH1T3CT0R7) **Created:** 2/6/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `fix/modelfile-whitespace-parsing` --- ### 📝 Commits (1) - [`2ed36e5`](https://github.com/ollama/ollama/commit/2ed36e5fefefd942bd9b599bd38bd160804259bc) parser: allow multiple spaces after PARAMETER and MESSAGE keywords ### 📊 Changes **2 files changed** (+43 additions, -7 deletions) <details> <summary>View changed files</summary> 📝 `parser/parser.go` (+15 -7) 📝 `parser/parser_test.go` (+28 -0) </details> ### 📄 Description ## Summary Fixes #13359 The Modelfile parser fails when there are multiple spaces between `PARAMETER`/`MESSAGE` keywords and their arguments: - `PARAMETER temperature 0.5` works - `PARAMETER temperature 0.5` fails with "unknown parameter ''" - `MESSAGE user hello` fails with "message role must be one of..." **Root cause:** In `ParseFile()`, when `stateParameter` or `stateMessage` transitions on a space character, the accumulated buffer is used as `cmd.Name` or role. If only spaces have been read since entering the state (buffer is empty), the transition fires prematurely with an empty string. **Fix:** Check if the buffer is empty before transitioning out of `stateParameter`/`stateMessage`. If empty, stay in the current state to skip leading whitespace. This is a minimal change (6 lines of logic) that only affects these two states — it does not touch `SYSTEM`, `FROM`, `ADAPTER`, or any triple-quote handling. ## Test plan - [x] Added test cases to `TestParseFileTrimSpace` with multiple spaces after `PARAMETER` - [x] Added test cases to `TestParseFileMessages` with multiple spaces after `MESSAGE` - [x] All existing parser tests pass (`go test ./parser/ -v` — 60+ tests) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
GiteaMirror added the pull-request label 2026-04-16 07:16:40 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/ollama#19798