pprof icon indicating copy to clipboard operation
pprof copied to clipboard

internal/graph: Escape labels to support double quotes

Open evanj opened this issue 3 years ago • 3 comments

Fixes syntax errors when trying to render pprof profiles that have double quotes in tags. These can be created with Go's pprof labels feature, for example with:

Fixes syntax errors when trying to render pprof profiles that have double quotes in tags. These can be created with Go's pprof labels feature, for example with:

pprof.Labels("key", "label "double quote"\nline two")

Trying to display a graph generated with this lable will fail:

Error: : syntax error in line 5 near 'quote'

The double quote (") was never escaped in the label strings. Add a new escaping function that replaces newlines with centered lines (\n) because the existing one replaces newline with left-justified lines (\l).

evanj avatar Mar 15 '22 15:03 evanj

This is a second attempt at #683. I started this as a new pull request because it takes a slightly different approach, so I was personally finding the commit history confusing instead of helpful.

evanj avatar Mar 15 '22 15:03 evanj

Codecov Report

Merging #689 (34b8741) into main (c488b8f) will increase coverage by 0.07%. The diff coverage is n/a.

@@            Coverage Diff             @@
##             main     #689      +/-   ##
==========================================
+ Coverage   63.70%   63.78%   +0.07%     
==========================================
  Files          41       41              
  Lines        6489     6492       +3     
==========================================
+ Hits         4134     4141       +7     
+ Misses       1913     1908       -5     
- Partials      442      443       +1     
Impacted Files Coverage Δ
...github.com/google/pprof/internal/graph/dotgraph.go 90.32% <0.00%> (+0.04%) :arrow_up:
...rc/github.com/google/pprof/internal/graph/graph.go 29.10% <0.00%> (+1.19%) :arrow_up:

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update c488b8f...34b8741. Read the comment docs.

codecov-commenter avatar Mar 15 '22 15:03 codecov-commenter

I believe this PR should fix the bug that was just reported to the Go project: https://github.com/golang/go/issues/53703 . The outstanding issue that I need to get back to is escaping non-printable characters, and adding a test for that case. I may not have time to get to that immediately. I think this PR doesn't make the handling of non-printable characters worse than it is today, but it would be nice to make this a "complete" fix. I will attempt to return to this change in the next couple of weeks.

evanj avatar Jul 07 '22 23:07 evanj