Parsing TXT records now works OK

This commit is contained in:
Miek Gieben 2012-02-12 22:24:18 +01:00
parent 6279bb1917
commit a7b2a88e7a
3 changed files with 65 additions and 57 deletions

View File

@ -207,7 +207,8 @@ func TestQuotes(t *testing.T) {
`t.example.com. IN TXT "abc" ( "DEF" )`: "t.example.com.\t3600\tIN\tTXT\t\"abc\" \"DEF\"", `t.example.com. IN TXT "abc" ( "DEF" )`: "t.example.com.\t3600\tIN\tTXT\t\"abc\" \"DEF\"",
`t.example.com. IN TXT aaa ;`: "t.example.com.\t3600\tIN\tTXT\t\"aaa \"", `t.example.com. IN TXT aaa ;`: "t.example.com.\t3600\tIN\tTXT\t\"aaa \"",
`t.example.com. IN TXT aaa aaa;`: "t.example.com.\t3600\tIN\tTXT\t\"aaa aaa\"", `t.example.com. IN TXT aaa aaa;`: "t.example.com.\t3600\tIN\tTXT\t\"aaa aaa\"",
// `t.example.com. IN TXT aaa`: "t.example.com.\t3600\tIN\tTXT\t\"aaa\"", `t.example.com. IN TXT aaa aaa`: "t.example.com.\t3600\tIN\tTXT\t\"aaa aaa\"",
`t.example.com. IN TXT aaa`: "t.example.com.\t3600\tIN\tTXT\t\"aaa\"",
// "cid.urn.arpa. NAPTR 100 50 \"s\" \"z3950+I2L+I2C\" \"\" _z3950._tcp.gatech.edu.": // "cid.urn.arpa. NAPTR 100 50 \"s\" \"z3950+I2L+I2C\" \"\" _z3950._tcp.gatech.edu.":
// "cid.urn.arpa.\t3600\tIN\tNAPTR\t100 50 \"s\" \"z3950+I2L+I2C\" \"\" _z3950._tcp.gatech.edu.", // "cid.urn.arpa.\t3600\tIN\tNAPTR\t100 50 \"s\" \"z3950+I2L+I2C\" \"\" _z3950._tcp.gatech.edu.",
// "cid.urn.arpa. NAPTR 100 50 \"s\" \"rcds+I2C\" \"\" _rcds._udp.gatech.edu.": // "cid.urn.arpa. NAPTR 100 50 \"s\" \"rcds+I2C\" \"\" _rcds._udp.gatech.edu.":

View File

@ -10,7 +10,7 @@ import (
) )
// Only used when debugging the parser itself. // Only used when debugging the parser itself.
var _DEBUG = true var _DEBUG = false
// Complete unsure about the correctness of this value? // Complete unsure about the correctness of this value?
// Large blobs of base64 code might get longer than this.... // Large blobs of base64 code might get longer than this....
@ -347,6 +347,8 @@ func (l lex) String() string {
return "S:" + l.token + "$" return "S:" + l.token + "$"
case _BLANK: case _BLANK:
return "_" return "_"
case _QUOTE:
return "\""
case _NEWLINE: case _NEWLINE:
return "|\n" return "|\n"
case _RRTYPE: case _RRTYPE:
@ -450,6 +452,12 @@ func zlexer(s scanner.Scanner, c chan lex) {
stri++ stri++
break break
} }
if stri > 0 {
l.value = _STRING
l.token = string(str[:stri])
c <- l
stri = 0
}
commt = true commt = true
case '\n': case '\n':
// Hmmm, escape newline // Hmmm, escape newline

View File

@ -709,28 +709,17 @@ func setTXT(h RR_Header, c chan lex, f string) (RR, *ParseError) {
// Get the remaining data until we see a NEWLINE // Get the remaining data until we see a NEWLINE
quote := false quote := false
quoted := false // unquoted strings are also allowed
l := <-c l := <-c
i := 0 var s []string
s := make([]string, i) switch l.value == _QUOTE {
if l.value == _QUOTE { case true: // A number of quoted string
quoted = true s = make([]string, 0)
}
for l.value != _NEWLINE && l.value != _EOF { for l.value != _NEWLINE && l.value != _EOF {
switch l.value { switch l.value {
case _STRING: case _STRING:
s = append(s, l.token) s = append(s, l.token)
i++
case _BLANK: case _BLANK:
if !quoted { if quote {
if i = 0 {
return nil, &ParseError{f, "bad TXT txt", l}
}
s[i-1] += l.token
l = <-c
continue
}
if quoted && quote {
// _BLANK can only be seen in between txt parts. // _BLANK can only be seen in between txt parts.
return nil, &ParseError{f, "bad TXT Txt", l} return nil, &ParseError{f, "bad TXT Txt", l}
} }
@ -741,6 +730,16 @@ func setTXT(h RR_Header, c chan lex, f string) (RR, *ParseError) {
} }
l = <-c l = <-c
} }
if quote {
return nil, &ParseError{f, "Bad TXT Txt", l}
}
case false: // Unquoted text record
s = make([]string, 1)
for l.value != _NEWLINE && l.value != _EOF {
s[0] += l.token
l = <-c
}
}
rr.Txt = s rr.Txt = s
return rr, nil return rr, nil
} }