Skip to content
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
29 changes: 29 additions & 0 deletions RELEASE.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,34 @@
# go-ethernetip Releases

## v0.8.1

**Date:** 2026-11-15
**Previous release:** v0.8.0

## Summary

A patch release on v0.8.0. No exported identifier is added, removed or
changed.

## Changes

### Fixes

- **eds**: `GenerateGo` writes `GenerateOptions.Source` into the header
comment as the other text of an EDS file is written into comments:
control characters, invalid UTF-8 and the byte order mark become spaces.
A source name with a line break made the header end early, so the
output did not format (an error) or held the rest of the name as code.
The header is now always the first line.

### Tests

- `TestGenerateSourceKeepsHeaderOneLine`: source names with LF, CR LF,
an escape sequence, U+2028, a backtick, invalid UTF-8 and `*/` give a
one-line header and the same file after it as a plain name.

---

## v0.8.0

**Date:** 2026-11-14
Expand Down
3 changes: 2 additions & 1 deletion docs/api/eds.md
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,8 @@ Section returns the section named name (case-insensitive), or nil.
type GenerateOptions struct {
// Package is the package name of the generated file; default "device".
Package string
// Source names the EDS file in the header comment.
// Source names the EDS file in the header comment. Control characters in it
// become spaces, so the header stays one line.
Source string
// License, when set, is written as an SPDX-License-Identifier line
// ("MIT"); the generated code is otherwise unlabelled, as its licence
Expand Down
5 changes: 3 additions & 2 deletions eds/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ import (
type GenerateOptions struct {
// Package is the package name of the generated file; default "device".
Package string
// Source names the EDS file in the header comment.
// Source names the EDS file in the header comment. Control characters in it
// become spaces, so the header stays one line.
Source string
// License, when set, is written as an SPDX-License-Identifier line
// ("MIT"); the generated code is otherwise unlabelled, as its licence
Expand Down Expand Up @@ -154,7 +155,7 @@ func (g *gen) header(dev Device, opts GenerateOptions) {
if src == "" {
src = "an EDS file"
}
g.p("// Code generated by go-ethernetip eds.GenerateGo from %s. DO NOT EDIT.\n\n", src)
g.p("// Code generated by go-ethernetip eds.GenerateGo from %s. DO NOT EDIT.\n\n", goComment(src))
if opts.License != "" {
g.p("// SPDX-License-Identifier: %s\n\n", strings.Map(func(r rune) rune {
if r == '\n' || r == '\r' {
Expand Down
26 changes: 26 additions & 0 deletions eds/generate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,32 @@ func TestGenerateGolden(t *testing.T) {
}
}

// The source name is a file name the caller passes on: whatever it holds, the
// header stays the first line and the declarations are those of a plain name.
func TestGenerateSourceKeepsHeaderOneLine(t *testing.T) {
plain, err := GenerateGo(sample(t), GenerateOptions{Source: "device.eds"})
if err != nil {
t.Fatal(err)
}
for _, src := range []string{"a\nb.eds", "a\r\nb.eds", "a\x1b[2Jb.eds", "a\u2028b`.eds", "a\xffb.eds", "a */ b.eds"} {
out, err := GenerateGo(sample(t), GenerateOptions{Source: src})
if err != nil {
t.Fatalf("source %q: %v", src, err)
}
first, rest, _ := bytes.Cut(out, []byte("\n"))
if !bytes.HasPrefix(first, []byte("// Code generated by go-ethernetip eds.GenerateGo from ")) || !bytes.HasSuffix(first, []byte(". DO NOT EDIT.")) {
t.Errorf("source %q: first line %q", src, first)
}
if bytes.ContainsFunc(first, func(r rune) bool { return r < 0x20 || r == 0x7f }) {
t.Errorf("source %q: control character in the header %q", src, first)
}
_, plainRest, _ := bytes.Cut(plain, []byte("\n"))
if !bytes.Equal(rest, plainRest) {
t.Errorf("source %q: the file after the header differs from the one for a plain name", src)
}
}
}

func TestGeneratePackage(t *testing.T) {
out, err := GenerateGo(sample(t), GenerateOptions{})
if err != nil {
Expand Down
Loading