Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
5d12f4d
Add leaks and vunerability checks
arran4 Sep 9, 2022
2c93a04
Requires secrets now
arran4 Sep 9, 2022
cb34d82
Renamed interface as it's useful own it's own. Made it public. Added …
arran4 Nov 6, 2022
84e95bc
Some suggestions, this could be improved still.
arran4 Jul 25, 2023
30c7458
Version bump required by this change.
arran4 Jul 25, 2023
4b365fb
19 too fails.
arran4 Jul 25, 2023
eca14a4
Should be able to distinguish unset from invalid time properties
brackendawson Sep 22, 2024
4251b08
Improve error for property not found
brackendawson Sep 25, 2024
ed74932
Remove deprecated ioutil
brackendawson Sep 25, 2024
efc12a1
Move targeted Go version to 1.20
brackendawson Sep 26, 2024
229e6a3
Merge pull request #98 from brackendawson/time-prop-err
arran4 Sep 26, 2024
e9a75cb
Add method to remove property
quite Aug 22, 2024
f364b80
Merge pull request #96 from quite/removeproperty
arran4 Sep 28, 2024
34998ad
Merge branch 'master' into pimtrace_changes
arran4 Sep 28, 2024
1c96d16
Merged
arran4 Sep 28, 2024
4e7b969
Merge pull request #59 from arran4/pimtrace_changes
arran4 Sep 28, 2024
ed4039d
Merge branch 'master' into govun
arran4 Sep 28, 2024
18b0c81
New tool
arran4 Sep 28, 2024
c9951e3
Merge pull request #58 from arran4/govun
arran4 Sep 28, 2024
77c6ce9
Merge remote-tracking branch 'manolotonto1/master' into err_change
arran4 Sep 29, 2024
db0e0a3
Merge branch 'master' into err_change
arran4 Sep 29, 2024
667ee73
Test fixed.
arran4 Sep 29, 2024
6aea8dc
Fixed test failure. (Error wrapping needed to be considered in EOF ch…
arran4 Sep 29, 2024
553e4d7
%s => %w fixes and an additional error.
arran4 Sep 29, 2024
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: 11 additions & 0 deletions .github/workflows/goleaks.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
name: gitleaks
on: [push,pull_request]
jobs:
gitleaks:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- name: gitleaks-action
uses: zricethezav/gitleaks-action@master
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
11 changes: 11 additions & 0 deletions .github/workflows/govun.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
name: Go vunderability check
on: [push, pull_request]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Setup Golang
uses: actions/setup-go@v5
- id: govulncheck
uses: golang/govulncheck-action@v1
26 changes: 22 additions & 4 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
on: [push, pull_request]
name: Test
jobs:
test:
version:
name: Test
permissions:
contents: read
strategy:
matrix:
go-version: ['1.14.15', '1.15.15', '1.16.15', '1.17.13', '1.22.3']
os: [ubuntu-latest, macos-13, windows-latest]
go-version: ['oldstable', 'stable']
os: ['ubuntu-latest', 'macos-13', 'windows-latest']
runs-on: ${{ matrix.os }}
steps:
- name: Checkout
Expand All @@ -18,4 +18,22 @@ jobs:
with:
go-version: "${{ matrix.go-version }}"
- name: Go Test
run: go test ./...
run: go test -race ./...
module:
name: Test
permissions:
contents: read
strategy:
matrix:
go-version-file: ['go.mod']
os: ['ubuntu-latest', 'macos-13', 'windows-latest']
runs-on: ${{ matrix.os }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Golang
uses: actions/setup-go@v5
with:
go-version-file: "${{ matrix.go-version-file }}"
- name: Go Test
run: go test -race ./...
43 changes: 25 additions & 18 deletions calendar.go
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ func (calendar *Calendar) SerializeTo(w io.Writer) error {
p.serialize(w)
}
for _, c := range calendar.Components {
c.serialize(w)
c.SerializeTo(w)
}
_, _ = fmt.Fprint(w, "END:VCALENDAR", "\r\n")
return nil
Expand Down Expand Up @@ -420,8 +420,8 @@ func ParseCalendar(r io.Reader) (*Calendar, error) {
for ln := 0; cont; ln++ {
l, err := cs.ReadLine()
if err != nil {
switch err {
case io.EOF:
switch {
case errors.Is(err, io.EOF):
cont = false
default:
return c, err
Expand All @@ -432,10 +432,10 @@ func ParseCalendar(r io.Reader) (*Calendar, error) {
}
line, err := ParseProperty(*l)
if err != nil {
return nil, fmt.Errorf("%s %d: %w", ParsingLineError, ln, err)
return nil, fmt.Errorf("%w %d: %w", ErrParsingLine, ln, err)
}
if line == nil {
return nil, fmt.Errorf("%s %d", ParsingCalendarLineError, ln)
return nil, fmt.Errorf("%w %d", ErrParsingCalendarLine, ln)
}
switch state {
case "begin":
Expand All @@ -445,10 +445,10 @@ func ParseCalendar(r io.Reader) (*Calendar, error) {
case "VCALENDAR":
state = "properties"
default:
return nil, errors.New(MalformedCalendarExpectedVCalendarError)
return nil, ErrMalformedCalendarExpectedVCalendar
}
default:
return nil, errors.New(MalformedCalendarExpectedBeginError)
return nil, ErrMalformedCalendarExpectedBegin
}
case "properties":
switch line.IANAToken {
Expand All @@ -457,7 +457,7 @@ func ParseCalendar(r io.Reader) (*Calendar, error) {
case "VCALENDAR":
state = "end"
default:
return nil, errors.New(MalformedCalendarExpectedEndError)
return nil, ErrMalformedCalendarExpectedEnd
}
case "BEGIN":
state = "components"
Expand All @@ -475,23 +475,23 @@ func ParseCalendar(r io.Reader) (*Calendar, error) {
case "VCALENDAR":
state = "end"
default:
return nil, errors.New(MalformedCalendarExpectedEndError)
return nil, fmt.Errorf("%w at '%s': %w", ErrMalformedCalendarExpectedEnd, line.IANAToken, err)
}
case "BEGIN":
co, err := GeneralParseComponent(cs, line)
if err != nil {
return nil, err
return nil, fmt.Errorf("%w at '%s': %w", ErrMalformedCalendarExpectedEnd, line.IANAToken, err)
}
if co != nil {
c.Components = append(c.Components, co)
}
default:
return nil, errors.New(MalformedCalendarExpectedBeginOrEndError)
return nil, fmt.Errorf("%w at '%s'", ErrMalformedCalendarExpectedBeginOrEnd, line.IANAToken)
}
case "end":
return nil, errors.New(MalformedCalendarUnexpectedEndError)
return nil, ErrMalformedCalendarUnexpectedEnd
default:
return nil, errors.New(MalformedCalendarBadStateError)
return nil, ErrMalformedCalendarBadState
}
}
return c, nil
Expand Down Expand Up @@ -529,7 +529,7 @@ func (cs *CalendarStream) ReadLine() (*ContentLine, error) {
}
p, err := cs.b.Peek(1)
r = append(r, b[:len(b)-o]...)
if err == io.EOF {
if errors.Is(err, io.EOF) {
c = false
}
if len(p) == 0 {
Expand All @@ -542,20 +542,27 @@ func (cs *CalendarStream) ReadLine() (*ContentLine, error) {
} else {
r = append(r, b...)
}
switch err {
case nil:
switch {
case err == nil:
if len(r) == 0 {
c = true
}
case io.EOF:
case errors.Is(err, io.EOF):
c = false
default:
// This must be as a result of boxing?
if err != nil {
err = fmt.Errorf("readline: %w", err)
}
return nil, err
}
}
if len(r) == 0 && err != nil {
return nil, err
return nil, fmt.Errorf("readline: %w", err)
}
cl := ContentLine(r)
if err != nil {
err = fmt.Errorf("readline: %w", err)
}
return &cl, err
}
24 changes: 12 additions & 12 deletions calendar_test.go
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
package ics

import (
"errors"
"github.com/stretchr/testify/assert"
"io"
"io/ioutil"
"os"
"path/filepath"
"regexp"
"strings"
"testing"
"time"
"unicode/utf8"

"github.com/stretchr/testify/assert"
)

func TestTimeParsing(t *testing.T) {
Expand All @@ -20,7 +19,7 @@ func TestTimeParsing(t *testing.T) {
t.Errorf("read file: %v", err)
}
cal, err := ParseCalendar(calFile)
if err != nil {
if err != nil && !errors.Is(err, io.EOF) {
t.Errorf("parse calendar: %v", err)
}

Expand Down Expand Up @@ -129,8 +128,8 @@ CLASS:PUBLIC
for i := 0; cont; i++ {
l, err := c.ReadLine()
if err != nil {
switch err {
case io.EOF:
switch {
case errors.Is(err, io.EOF):
cont = false
default:
t.Logf("Unknown error; %v", err)
Expand All @@ -139,7 +138,7 @@ CLASS:PUBLIC
}
}
if l == nil {
if err == io.EOF && i == len(expected) {
if errors.Is(err, io.EOF) && i == len(expected) {
cont = false
} else {
t.Logf("Nil response...")
Expand Down Expand Up @@ -168,14 +167,15 @@ func TestRfc5545Sec4Examples(t *testing.T) {
return nil
}

inputBytes, err := ioutil.ReadFile(path)
inputBytes, err := os.ReadFile(path)
if err != nil {
return err
}

input := rnReplace.ReplaceAllString(string(inputBytes), "\r\n")
structure, err := ParseCalendar(strings.NewReader(input))
if assert.Nil(t, err, path) {
if err != nil && !errors.Is(err, io.EOF) {
assert.Nil(t, err, path)
// This should fail as the sample data doesn't conform to https://tools.ietf.org/html/rfc5545#page-45
// Probably due to RFC width guides
assert.NotNil(t, structure)
Expand Down Expand Up @@ -373,7 +373,7 @@ END:VCALENDAR
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
c, err := ParseCalendar(strings.NewReader(tc.input))
if !assert.NoError(t, err) {
if !errors.Is(err, io.EOF) && !assert.NoError(t, err) {
return
}

Expand All @@ -394,12 +394,12 @@ func TestIssue52(t *testing.T) {
_, fn := filepath.Split(path)
t.Run(fn, func(t *testing.T) {
f, err := os.Open(path)
if err != nil {
if err != nil && errors.Is(err, io.EOF) {
t.Fatalf("Error reading file: %s", err)
}
defer f.Close()

if _, err := ParseCalendar(f); err != nil {
if _, err := ParseCalendar(f); err != nil && !errors.Is(err, io.EOF) {
t.Fatalf("Error parsing file: %s", err)
}

Expand Down
Loading