Skip to content

Fix $__multiVar for values that contain spaces - #814

Merged
adamyeats merged 1 commit into
grafana:mainfrom
RaphaelFakhri:fix/multivar-quote-values
Nov 13, 2026
Merged

adamyeats merged 1 commit into
grafana:mainfrom
RaphaelFakhri:fix/multivar-quote-values

Conversation

@RaphaelFakhri

Copy link
Copy Markdown
Contributor

Type of Change

  • 🚀 Feature
  • 🐛 Bug Fix
  • 📝 Documentation
  • 🧹 Refactor / Chore

Bug Fix

What is the bug?

$__multiVar(qualifier,$var) writes each selected value as qualifier:value without quotes. When a value contains a space, GitHub search reads only the first word as the qualifier value and treats the rest as free text. For example, selecting the labels good first issue and bug expands to label:good first issue label:bug, which searches for the label good plus the text first issue, so the query misses the issues labeled good first issue.

This change wraps values that contain whitespace in double quotes, so the same selection expands to label:"good first issue" label:bug. Values that are already quoted and values without spaces are unchanged.

How to reproduce

  1. Expand the macro: is:open $__multiVar(label,$labels) with labels set to good first issue and bug produces is:open label:good first issue label:bug.
  2. Run both forms against the GitHub search API, for example on grafana/grafana: is:open label:good first issue returns 0 issues, and is:open label:"good first issue" returns 18.

Related Issues

Closes #813

Environment (if no related issue)

  • GitHub version: github.com
  • Plugin version: 2.9.3 (current main)

Please check that:

  • Tests for this change have been added/updated.
  • Documentation has been added/updated (where applicable).

Special notes for your reviewer

The quoting happens in the backend macro, so it applies to every query type that interpolates macros. The new cases in TestInterPolateMacros cover a value with spaces and a value that is already quoted.

@RaphaelFakhri
RaphaelFakhri requested a review from a team as a code owner October 20, 2026 12:41
Copilot AI lite review requested due to automatic review settings October 20, 2026 12:41
@cla-assistant

cla-assistant Bot commented Oct 20, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

Escape embedded quotes and backslashes and add a regression test.

1 open issue
What changed in this PR

Fixes $__multiVar so multi-word values are quoted for GitHub search.

Changes:

  • Added quoting for whitespace-containing values.
  • Added interpolation tests.
  • Updated template-variable documentation.

A remaining moderate issue is that embedded quotes and backslashes are not escaped before wrapping values.

File Summary
pkg/​github/​macros.go Quotes whitespace-containing qualifier values.
pkg/​github/​macros_test.go Tests new quoting behavior.
docs/​sources/​template-variables.md Documents quoted values.

Review effort: Lite

Comment thread pkg/github/macros.go Resolved
@adamyeats adamyeats closed this Nov 13, 2026
@adamyeats adamyeats reopened this Nov 13, 2026

@adamyeats adamyeats left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@RaphaelFakhri LGTM, thanks! Keeping already-quoted values as they are is a nice touch, since it doesn't break anyone who quoted them by hand.

@adamyeats adamyeats self-assigned this Nov 13, 2026
@adamyeats
adamyeats merged commit 3e3e732 into grafana:main Nov 13, 2026
38 of 40 checks passed
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.

Bug: $__multiVar breaks on variable values that contain spaces

3 participants