[PR #15705] model/parsers/qwen3coder: prevent tag regex from matching across newlines #61968

Open
opened 2026-04-29 16:56:09 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/ollama/ollama/pull/15705
Author: @mverrilli
Created: 4/19/2026
Status: 🔄 Open

Base: mainHead: fix/issue-15574-qwen3coder-xml-multiline-tag-match


📝 Commits (1)

  • 824f176 model/parsers/qwen3coder: prevent tag regex from matching across newlines

📊 Changes

2 files changed (+66 additions, -1 deletions)

View changed files

📝 model/parsers/qwen3coder.go (+3 -1)
📝 model/parsers/qwen3coder_test.go (+63 -0)

📄 Description

Summary

Fixes #15574.

The qwenTagRegex pattern <(\w+)=([^>]+)> was used to transform Qwen3-coder's custom XML-like tag syntax (e.g. <parameter=name>) into valid XML. The character class [^>] matches any character except >, including newlines. When a parameter value contains a <word= pattern (e.g. BBC BASIC code like IF C<1w=P-SQR(1-C)), the regex would greedily span multiple lines—consuming the actual </parameter> closing tag—until it hit the > in </function>. This produced malformed XML that failed to parse with: element <parameter> closed by </function>.

The fix is a one-character change: [^>]+[^>\n]+, restricting the regex to single-line matching. Since Qwen3-coder's format always puts each tag on its own line, this is the correct constraint.

Test plan

  • TestQwenXMLTransform: new case verifies < in parameter values is escaped correctly and closing tags are not consumed
  • TestQwen3CoderParserAngleBracketsInParameterValue: end-to-end test using BBC BASIC code from the issue report
  • Both tests fail against the old regex and pass with the fix
  • go test ./model/parsers/... passes

🔄 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/15705 **Author:** [@mverrilli](https://github.com/mverrilli) **Created:** 4/19/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `fix/issue-15574-qwen3coder-xml-multiline-tag-match` --- ### 📝 Commits (1) - [`824f176`](https://github.com/ollama/ollama/commit/824f1768b26828eb0a9f937bfef41fba723db636) model/parsers/qwen3coder: prevent tag regex from matching across newlines ### 📊 Changes **2 files changed** (+66 additions, -1 deletions) <details> <summary>View changed files</summary> 📝 `model/parsers/qwen3coder.go` (+3 -1) 📝 `model/parsers/qwen3coder_test.go` (+63 -0) </details> ### 📄 Description ## Summary Fixes #15574. The `qwenTagRegex` pattern `<(\w+)=([^>]+)>` was used to transform Qwen3-coder's custom XML-like tag syntax (e.g. `<parameter=name>`) into valid XML. The character class `[^>]` matches any character except `>`, including newlines. When a parameter value contains a `<word=` pattern (e.g. BBC BASIC code like `IF C<1w=P-SQR(1-C)`), the regex would greedily span multiple lines—consuming the actual `</parameter>` closing tag—until it hit the `>` in `</function>`. This produced malformed XML that failed to parse with: `element <parameter> closed by </function>`. The fix is a one-character change: `[^>]+` → `[^>\n]+`, restricting the regex to single-line matching. Since Qwen3-coder's format always puts each tag on its own line, this is the correct constraint. ## Test plan - `TestQwenXMLTransform`: new case verifies `<` in parameter values is escaped correctly and closing tags are not consumed - `TestQwen3CoderParserAngleBracketsInParameterValue`: end-to-end test using BBC BASIC code from the issue report - Both tests fail against the old regex and pass with the fix - `go test ./model/parsers/...` passes --- <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-29 16:56:09 -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#61968