miekg/dns — pull request #85 by andrewtj (2014-02-26 11:03:41+00:00)
Title: Parsing and Stringer Changes

In belated follow-up to the issues raised in #75:

At the minute when domains are put on the wire `\DDD` escapes are converted to a single byte with overflows not being treated as errors. Incomplete `\D` or `\DD` escapes are treated as regular escapes. From the wire, [literal dots, < 32 and >= 127](https://github.com/miekg/dns/blob/master/msg.go#L399-L404) are escaped. RR Stringer methods then use domain name strings as-is.

TXT character strings are put to and taken from the wire as-is. RR Stringer methods use `strconv.QuoteToASCII` to escape strings. `strconv`'s unquote functions aren't used to parse TXT character strings.

I think it'd make sense to instead only escape literal dots when taking domain names from the wire and to then escape domain names and character strings (1035-style) in RR Stringer methods. I think this is a bit more consistent and is easier to work with as the strings are always in an unambiguous form. The only special handling to keep in mind is limited to length requirements and the meaning of dots and escaped dots in domain names.

I'd also like to propose making the Stringers output comments rather if a record is in a bad state (too long a DNS label/domain, empty labels, too long a TXT record, etc) so that the library never outputs anything it can't parse. Along with this a `ToString()` method that returns `(string, error)` would probably be worthwhile.

If that sounds reasonable I'll start chipping away at it.