Fix parsing text array with negative bounds

e.g. '[-4:-2]={1,2,3}'

fixes #132
This commit is contained in:
Jack Christensen 2021-10-30 09:00:48 -05:00
parent b72f8084b5
commit 2caf113f1b
2 changed files with 9 additions and 1 deletions

View File

@ -305,7 +305,7 @@ func arrayParseInteger(buf *bytes.Buffer) (int32, error) {
return 0, err
}
if '0' <= r && r <= '9' {
if ('0' <= r && r <= '9') || r == '-' {
s.WriteRune(r)
} else {
buf.UnreadRune()

View File

@ -100,6 +100,14 @@ func TestParseUntypedTextArray(t *testing.T) {
},
},
},
{
source: "[-4:-2]={1,2,3}",
result: pgtype.UntypedTextArray{
Elements: []string{"1", "2", "3"},
Quoted: []bool{false, false, false},
Dimensions: []pgtype.ArrayDimension{{Length: 3, LowerBound: -4}},
},
},
}
for i, tt := range tests {