[PR #12358] [MERGED] parsers: fix &s in qwen3coder parameter values #13796

Closed
opened 2026-04-13 00:36:47 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/ollama/ollama/pull/12358
Author: @drifkin
Created: 9/20/2025
Status: Merged
Merged: 9/20/2025
Merged by: @drifkin

Base: mainHead: drifkin/qwen3-coder-ampersands


📝 Commits (1)

  • 242df70 parsers: fix &s in qwen3coder parameter values

📊 Changes

2 files changed (+87 additions, -2 deletions)

View changed files

📝 model/parsers/qwen3coder.go (+39 -2)
📝 model/parsers/qwen3coder_test.go (+48 -0)

📄 Description

In https://github.com/ollama/ollama/issues/12357 we that the model will output tool calls such as

<function=shell>
<parameter=command>
pwd && ls -la
</parameter>
</function>

We parse this using the approach of transforming into valid xml and then using an xml parser. While we do transform the function and parameter names, we weren't escaping the parameter values (which in this example are invalid since pwd && ls -la contains unescaped ampersands).

This has been fixed by first transforming the tags in the same way, and then walking the transformed string and escaping the text in between the tags. This also fixes a case where < in the middle of a parameter value would cause an xml parse failure.

Fixes: #12357


🔄 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/12358 **Author:** [@drifkin](https://github.com/drifkin) **Created:** 9/20/2025 **Status:** ✅ Merged **Merged:** 9/20/2025 **Merged by:** [@drifkin](https://github.com/drifkin) **Base:** `main` ← **Head:** `drifkin/qwen3-coder-ampersands` --- ### 📝 Commits (1) - [`242df70`](https://github.com/ollama/ollama/commit/242df70a759695dc258c00f56fa373ab5c06b8b2) parsers: fix `&`s in qwen3coder parameter values ### 📊 Changes **2 files changed** (+87 additions, -2 deletions) <details> <summary>View changed files</summary> 📝 `model/parsers/qwen3coder.go` (+39 -2) 📝 `model/parsers/qwen3coder_test.go` (+48 -0) </details> ### 📄 Description In <https://github.com/ollama/ollama/issues/12357> we that the model will output tool calls such as ``` <function=shell> <parameter=command> pwd && ls -la </parameter> </function> ``` We parse this using the approach of transforming into valid xml and then using an xml parser. While we do transform the function and parameter names, we weren't escaping the parameter values (which in this example are invalid since `pwd && ls -la` contains unescaped ampersands). This has been fixed by first transforming the tags in the same way, and then walking the transformed string and escaping the text in between the tags. This also fixes a case where `<` in the middle of a parameter value would cause an xml parse failure. Fixes: #12357 --- <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-13 00:36:47 -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#13796