Skip to content

Commit 91cafac

Browse files
authored
fix: preserve URL query strings in invoke output (#54)
## Summary - Fixes pretty-printed `kernel invoke` output escaping `&` as `\\u0026` (and similarly `<`, `>`), which breaks copy/paste of URLs returned in invocation output (e.g. replay URLs). - Switches JSON pretty-printing to a custom encoder with `SetEscapeHTML(false)`. ## Why Go's default `json.MarshalIndent` escapes HTML-sensitive characters. When the CLI re-marshals invocation output for pretty printing, URLs like `...?jwt=...&replay_id=...` can show up as `...?jwt=...\\u0026replay_id=...`. ## Test plan - `go test ./...` <!-- CURSOR_SUMMARY --> --- > [!NOTE] > Prevents HTML character escaping in pretty-printed invoke results by using a custom JSON encoder to preserve URL characters. > > - **CLI – `cmd/invoke.go`**: > - Use custom JSON encoder for `printResult` with `SetEscapeHTML(false)` and indentation to avoid escaping `&`, `<`, `>` in pretty-printed output; trims trailing newline. > > <sup>Written by [Cursor Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit f3502a4. This will update automatically on new commits. Configure [here](https://cursor.com/dashboard?tab=bugbot).</sup> <!-- /CURSOR_SUMMARY -->
1 parent ce0cf8c commit 91cafac

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

cmd/invoke.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package cmd
22

33
import (
4+
"bytes"
45
"context"
56
"encoding/json"
67
"fmt"
@@ -194,8 +195,15 @@ func handleSdkError(err error) error {
194195
func printResult(success bool, output string) {
195196
var prettyJSON map[string]interface{}
196197
if err := json.Unmarshal([]byte(output), &prettyJSON); err == nil {
197-
bs, _ := json.MarshalIndent(prettyJSON, "", " ")
198-
output = string(bs)
198+
// Use a custom encoder to prevent escaping &, <, > as \u0026, \u003c, \u003e
199+
// which breaks copy/paste of URLs in the invoke output.
200+
var buf bytes.Buffer
201+
encoder := json.NewEncoder(&buf)
202+
encoder.SetEscapeHTML(false)
203+
encoder.SetIndent("", " ")
204+
if err := encoder.Encode(prettyJSON); err == nil {
205+
output = strings.TrimSuffix(buf.String(), "\n")
206+
}
199207
}
200208
// use pterm.Success if succeeded, pterm.Error if failed
201209
if success {

0 commit comments

Comments
 (0)