mirror of
				https://github.com/golang/go.git
				synced 2025-10-31 16:50:58 +00:00 
			
		
		
		
	net: concatenate multiple TXT strings in single TXT record
When go resolver was changed to use dnsmessage.Parser, LookupTXT returned two strings in one record as two different records. This change reverts back to concatenating multiple strings in a single TXT record. Fixes #27763 Change-Id: Ice226fcb2be4be58853de34ed35b4627acb429ea Reviewed-on: https://go-review.googlesource.com/136955 Reviewed-by: Ian Gudger <igudger@google.com> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> Run-TryBot: Ian Gudger <igudger@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org>
This commit is contained in:
		
							parent
							
								
									31d19c0ba3
								
							
						
					
					
						commit
						a6df1cece7
					
				
					 2 changed files with 67 additions and 4 deletions
				
			
		|  | @ -1568,3 +1568,56 @@ func TestDNSDialTCP(t *testing.T) { | |||
| 		t.Fatal("exhange failed:", err) | ||||
| 	} | ||||
| } | ||||
| 
 | ||||
| // Issue 27763: verify that two strings in one TXT record are concatenated. | ||||
| func TestTXTRecordTwoStrings(t *testing.T) { | ||||
| 	fake := fakeDNSServer{ | ||||
| 		rh: func(n, _ string, q dnsmessage.Message, _ time.Time) (dnsmessage.Message, error) { | ||||
| 			r := dnsmessage.Message{ | ||||
| 				Header: dnsmessage.Header{ | ||||
| 					ID:       q.Header.ID, | ||||
| 					Response: true, | ||||
| 					RCode:    dnsmessage.RCodeSuccess, | ||||
| 				}, | ||||
| 				Questions: q.Questions, | ||||
| 				Answers: []dnsmessage.Resource{ | ||||
| 					{ | ||||
| 						Header: dnsmessage.ResourceHeader{ | ||||
| 							Name:  q.Questions[0].Name, | ||||
| 							Type:  dnsmessage.TypeA, | ||||
| 							Class: dnsmessage.ClassINET, | ||||
| 						}, | ||||
| 						Body: &dnsmessage.TXTResource{ | ||||
| 							TXT: []string{"string1 ", "string2"}, | ||||
| 						}, | ||||
| 					}, | ||||
| 					{ | ||||
| 						Header: dnsmessage.ResourceHeader{ | ||||
| 							Name:  q.Questions[0].Name, | ||||
| 							Type:  dnsmessage.TypeA, | ||||
| 							Class: dnsmessage.ClassINET, | ||||
| 						}, | ||||
| 						Body: &dnsmessage.TXTResource{ | ||||
| 							TXT: []string{"onestring"}, | ||||
| 						}, | ||||
| 					}, | ||||
| 				}, | ||||
| 			} | ||||
| 			return r, nil | ||||
| 		}, | ||||
| 	} | ||||
| 	r := Resolver{PreferGo: true, Dial: fake.DialContext} | ||||
| 	txt, err := r.lookupTXT(context.Background(), "golang.org") | ||||
| 	if err != nil { | ||||
| 		t.Fatal("LookupTXT failed:", err) | ||||
| 	} | ||||
| 	if want := 2; len(txt) != want { | ||||
| 		t.Fatalf("len(txt), got %d, want %d", len(txt), want) | ||||
| 	} | ||||
| 	if want := "string1 string2"; txt[0] != want { | ||||
| 		t.Errorf("txt[0], got %q, want %q", txt[0], want) | ||||
| 	} | ||||
| 	if want := "onestring"; txt[1] != want { | ||||
| 		t.Errorf("txt[1], got %q, want %q", txt[1], want) | ||||
| 	} | ||||
| } | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Matthew Waters
						Matthew Waters