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 345a704 commit 37e29fe
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions senml.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +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 {
r.Name = replaceInvalidCharacters(r.Name)
}

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

Please sign in to comment.