Skip to content

Commit

Permalink
Update senml.go
Browse files Browse the repository at this point in the history
  • Loading branch information
ftylitak authored Nov 1, 2023
1 parent 37e29fe commit 283a528
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions senml.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package senml

import (
"encoding/json"
"encoding/xml"
"errors"
"fmt"
"sort"

"github.com/fxamacker/cbor/v2"
Expand Down Expand Up @@ -140,10 +140,10 @@ func replaceInvalidCharacters(name string) string {
// The base fields apply to the entries in the Record and also to all Records after
// it up to, but not including, the next Record that has that same base field.
func Normalize(p Pack) (Pack, error) {
for i, r := range p.Records {
for _, r := range p.Records {
r.Name = replaceInvalidCharacters(r.Name)
}

// Validate ensures that all the BaseVersions are equal.
if err := Validate(p); err != nil {
return Pack{}, err
Expand All @@ -167,7 +167,7 @@ func Normalize(p Pack) (Pack, error) {
if len(r.BaseName) > 0 {
bname = r.BaseName
}
r.Name = bname + r.Name
r.Name = replaceInvalidCharacters(bname + r.Name)
r.Time = btime + r.Time
if r.Sum != nil {
*r.Sum = bsum + *r.Sum
Expand Down Expand Up @@ -223,7 +223,7 @@ func Validate(p Pack) error {
if len(name) == 0 {
return ErrEmptyName
}

var valCnt int
if r.Value != nil {
valCnt++
Expand Down Expand Up @@ -258,10 +258,10 @@ func validateName(name string) error {
if (l == '-') || (l == ':') || (l == '.') || (l == '/') || (l == '_') {
return ErrBadChar
}
for _, l := range name {
if (l < 'a' || l > 'z') && (l < 'A' || l > 'Z') && (l < '0' || l > '9') && (l != '-') && (l != ':') && (l != '.') && (l != '/') && (l != '_') {
return ErrBadChar
}
}
//for _, l := range name {
// if (l < 'a' || l > 'z') && (l < 'A' || l > 'Z') && (l < '0' || l > '9') && (l != '-') && (l != ':') && (l != '.') && (l != '/') && (l != '_') {
// return ErrBadChar
// }
//}
return nil
}

0 comments on commit 283a528

Please sign in to comment.