From b2f37a159fbc878ec08a0d0bd798e3adf5d5c8b5 Mon Sep 17 00:00:00 2001 From: Tom Limoncelli Date: Mon, 20 Jun 2022 11:09:05 -0400 Subject: [PATCH 1/3] NewRR does not remove escape char --- parse_test.go | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/parse_test.go b/parse_test.go index 6c2563e06..8193447aa 100644 --- a/parse_test.go +++ b/parse_test.go @@ -144,6 +144,27 @@ func TestTXTEscapeParsing(t *testing.T) { } } +func TestTXTEscapeJustParse(t *testing.T) { + test := [][]string{ + {`unquoted`, `unquoted`}, + {`"quoted"`, `quoted`}, + {`"escaped\"quote"`, `escaped\"quote`}, // This passes. It shouldn't? + //{`"escaped\"quote"`, `escaped"quote`}, // This fails. It shouldn't? + } + for _, s := range test { + rr, err := NewRR(fmt.Sprintf("example.com. IN TXT %v", s[0])) + if err != nil { + t.Errorf("could not parse %v TXT: %s", s[0], err) + continue + } + + parsed := rr.(*TXT).Txt[0] + if parsed != s[1] { + t.Errorf("mismatch after parsing `%v` TXT record: `%v` != `%v`", s[0], parsed, s[1]) + } + } +} + func GenerateDomain(r *rand.Rand, size int) []byte { dnLen := size % 70 // artificially limit size so there's less to interpret if a failure occurs var dn []byte From c5d5afae7cbacc092a38e28686ea47046627c790 Mon Sep 17 00:00:00 2001 From: Tom Limoncelli Date: Mon, 20 Jun 2022 11:19:25 -0400 Subject: [PATCH 2/3] demonstrate bug --- parse_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/parse_test.go b/parse_test.go index 8193447aa..eb0141f36 100644 --- a/parse_test.go +++ b/parse_test.go @@ -149,7 +149,7 @@ func TestTXTEscapeJustParse(t *testing.T) { {`unquoted`, `unquoted`}, {`"quoted"`, `quoted`}, {`"escaped\"quote"`, `escaped\"quote`}, // This passes. It shouldn't? - //{`"escaped\"quote"`, `escaped"quote`}, // This fails. It shouldn't? + {`"escaped\"quote"`, `escaped"quote`}, // This fails. It shouldn't? } for _, s := range test { rr, err := NewRR(fmt.Sprintf("example.com. IN TXT %v", s[0])) From 47f52288549b2052353800cd7e3440dd61b50ffa Mon Sep 17 00:00:00 2001 From: Tom Limoncelli Date: Mon, 20 Nov 2023 08:34:04 -0500 Subject: [PATCH 3/3] More tests after re-reading the RFC --- parse_test.go | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/parse_test.go b/parse_test.go index 65a6df60f..20fe9a6ac 100644 --- a/parse_test.go +++ b/parse_test.go @@ -148,8 +148,19 @@ func TestTXTEscapeJustParse(t *testing.T) { test := [][]string{ {`unquoted`, `unquoted`}, {`"quoted"`, `quoted`}, - {`"escaped\"quote"`, `escaped\"quote`}, // This passes. It shouldn't? - {`"escaped\"quote"`, `escaped"quote`}, // This fails. It shouldn't? + //{`inner"quote`, `inner"quote`}, // Parse error + //{`"quoted"quote"`, `quoted"quote`}, // Parse error + {`"innerescaped\"quote"`, `innerescaped"quote`}, + {`1back\slash`, `1back\slash`}, + {`2back\\slash`, `2back\\slash`}, + {`3back\\\slash`, `3back\\\slash`}, + {`4back\\\\slash`, `4back\\\\slash`}, + {`5back\\\\\slash`, `5back\\\\\slash`}, + {`"q1back\slash"`, `1backslash`}, + {`"q2back\\slash"`, `2back\slash`}, + {`"q3back\\\slash"`, `3back\slash`}, + {`"q4back\\\\slash"`, `4back\\slash`}, + {`"q5back\\\\\slash"`, `5back\\slash`}, } for _, s := range test { rr, err := NewRR(fmt.Sprintf("example.com. IN TXT %v", s[0]))