From 82e55cd56044558e1303a2ec68ecbd0e8bc52b50 Mon Sep 17 00:00:00 2001 From: Bjoern Rabenstein Date: Wed, 14 May 2014 18:46:58 +0200 Subject: [PATCH] Fix docstring escaping. Change-Id: Ib8c8658795c9e2b0fa1a9321d7cbdef7ad4f2745 --- text/create_test.go | 4 ++-- text/parse.go | 4 +++- text/parse_test.go | 4 ++-- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/text/create_test.go b/text/create_test.go index c08d421..6c6fc3f 100644 --- a/text/create_test.go +++ b/text/create_test.go @@ -33,7 +33,7 @@ func testCreate(t test.Tester) { { in: &dto.MetricFamily{ Name: proto.String("name"), - Help: proto.String("doc string"), + Help: proto.String("two-line\n doc string"), Type: dto.MetricType_COUNTER.Enum(), Metric: []*dto.Metric{ &dto.Metric{ @@ -69,7 +69,7 @@ func testCreate(t test.Tester) { }, }, }, - out: `# HELP name doc string + out: `# HELP name two-line\n doc string # TYPE name counter name{labelname="val1",basename="basevalue"} NaN name{labelname="val2",basename="basevalue"} 0.23 1234567890 diff --git a/text/parse.go b/text/parse.go index f76ec3a..009e39c 100644 --- a/text/parse.go +++ b/text/parse.go @@ -422,7 +422,9 @@ func (p *Parser) readingHelp() stateFn { if p.readTokenUntilNewline(); p.err != nil { return nil // Unexpected end of input. } - p.currentMF.Help = proto.String(p.currentToken.String()) + p.currentMF.Help = proto.String( + strings.Replace(p.currentToken.String(), `\n`, "\n", -1), + ) return p.startOfLine } diff --git a/text/parse_test.go b/text/parse_test.go index 2fcb14d..9e176cf 100644 --- a/text/parse_test.go +++ b/text/parse_test.go @@ -91,7 +91,7 @@ no_labels{} 3 # TYPE name counter name{labelname="val1",basename="basevalue"} NaN name {labelname="val2",basename="base\"v\\al\nue"} 0.23 1234567890 -# HELP name doc string +# HELP name two-line\n doc string # HELP name2 doc string 2 # TYPE name2 gauge @@ -101,7 +101,7 @@ name2{ labelname = "val1" }-Inf out: []*dto.MetricFamily{ &dto.MetricFamily{ Name: proto.String("name"), - Help: proto.String("doc string"), + Help: proto.String("two-line\n doc string"), Type: dto.MetricType_COUNTER.Enum(), Metric: []*dto.Metric{ &dto.Metric{