Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pkg/rec: fix parser crash #97

Merged
merged 3 commits into from
Oct 2, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 4 additions & 7 deletions pkg/rec/rec.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,23 +90,20 @@ func (r *Rec) Copy() *Rec {
}

// normalizePath does path normalization as described in the docs.
// It happens in one linear pass along the string. Pointers are used for input and output to save time on data copying.
func normalizePath(s string) string {
if len(s) == 0 {
res := ""
return res
return ""
}

start := 0
for ; s[start] == '.' && start < len(s); start++ {
for ; start < len(s) && s[start] == '.'; start++ {
}
if start == len(s) {
res := ""
return res
return ""
}

end := len(s) - 1
for ; s[end] == '.' && end >= 0; end-- {
for ; end >= 0 && s[end] == '.'; end-- {
}
// check for string consisting only of points was done before

Expand Down
10 changes: 10 additions & 0 deletions pkg/rec/rec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,16 @@ func TestRec(t *testing.T) {
RawTime: "12345",
},
},
{
s: ". 0 0",
res: Rec{
Path: "",
Val: 0,
RawVal: "0",
Time: 0,
RawTime: "0",
},
},
}
nowF := func() time.Time {
return time.Time{}
Expand Down