Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

prompt-template textCleanRegex strips a leading or trailing quote that is part of the extracted message

Aperta Adatta ai principianti
#3,917 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
80/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
go
Ambito
backend

Direzione di ricerca

Inizia nella policy prompt-template, in extractStringAtPath, dove textCleanRegex viene applicata alle stringhe restituite da ExtractStringValueFromJsonpath; l’issue include un test di regressione e il comando go test . -run TestExtractStringAtPathStripsBoundaryQuotes -v. Rimuovi la rimozione involontaria delle virgolette e conferma che le stringhe estratte conservino le virgolette ai bordi. Controlla escapeForJSONString separatamente per preservarne il comportamento previsto di incorporamento in JSON.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Description

prompt-template uses the same ^"|"$ cleaner as content-length-guardrail:

textCleanRegex = regexp.MustCompile(`^"|"$`)

In extractStringAtPath, after ExtractStringValueFromJsonpath already returns a Go string (quotes not part of JSON encoding), the cleaner runs:

extractedValue = textCleanRegex.ReplaceAllString(extractedValue, "")

So a user message whose text is "hello world" (quotes included), or that merely starts with ", loses those characters before template substitution. That corrupts prompts that intentionally begin or end with a quotation mark (dialogue, JSON snippets, quoted speech).

This is the same regex class of bug as content-length-guardrail (#3911), in a different policy (prompt-template), on the extract path used whenever jsonPath is set (default message content paths).

Steps to reproduce

  1. On gateway-controllers main (4cf9570), in policies/prompt-template:
func TestExtractStringAtPathStripsBoundaryQuotes(t *testing.T) {
    got := textCleanRegex.ReplaceAllString(`"hello world"`, "")
    if got != "hello world" {
        t.Fatalf("fully quoted message became %q", got)
    }
    got2 := textCleanRegex.ReplaceAllString(`"starts with quote`, "")
    if got2 != "starts with quote" {
        t.Fatalf("leading quote stripped: got %q", got2)
    }
}
  1. go test . -run TestExtractStringAtPathStripsBoundaryQuotes -v

(The same ReplaceAllString is what extractStringAtPath applies to every extracted string.)

Expected behavior

Extracted string content is left unchanged. JSON string encoding is already handled by ExtractStringValueFromJsonpath returning a string.

Actual behavior

fully quoted -> hello world   (both boundary quotes removed)
leading-only -> starts with quote

Environment

  • gateway-controllers commit: main @ 4cf9570 (filed against api-platform)
  • Policy: prompt-template
  • OS: Linux x86_64

Related issues / PRs

#3911 documents the identical regex in content-length-guardrail. #695 is a generic "Prompt Template Policy Issue" pointer with no reproduction of quote stripping. No open/closed issue or open PR for prompt-template textCleanRegex.

Possible Solution

Remove textCleanRegex.ReplaceAllString from extractStringAtPath (and review escapeForJSONString, which strips the outer quotes of json.Marshal output — that path is intentional for embedding, but must not use a pattern that also deletes an interior boundary quote from non-Marshal input). Prefer json.Marshal + slicing s[1:len(s)-1] when stripping Marshal's outer quotes. Add the regression test above.

I'm happy to send a PR.

Lingua principale
Go
Stelle
79
Fork
130
Merge medio
2g 2h
PR unite (30g)
157

Preparare l'ambiente

  • Nessun Dockerfile né file Docker Compose
  • Ha un modello di pull request
  • Nessuna guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di wso2/api-platform

Tutte le issue di wso2/api-platform

Issue simili

Altre issue su Go

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.