Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: goccy/go-yaml
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v1.11.1
Choose a base ref
...
head repository: goccy/go-yaml
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v1.11.2
Choose a head ref
  • 12 commits
  • 17 files changed
  • 4 contributors

Commits on Sep 14, 2023

  1. update CHANGELOG

    goccy committed Sep 14, 2023
    Copy the full SHA
    a272670 View commit details
  2. Copy the full SHA
    680ea24 View commit details
  3. Update issue templates

    goccy authored Sep 14, 2023
    Copy the full SHA
    30e963d View commit details
  4. create pull request template

    goccy committed Sep 14, 2023
    Copy the full SHA
    5b5e7e0 View commit details
  5. Update issue templates

    goccy authored Sep 14, 2023
    Copy the full SHA
    1c0fdf0 View commit details

Commits on Sep 15, 2023

  1. Fix quoted comments (#370)

    * Make path filtering work with quotes
    WillAbides authored Sep 15, 2023
    Copy the full SHA
    4df8923 View commit details
  2. Copy the full SHA
    957e9d7 View commit details
  3. update CHANGELOG

    goccy committed Sep 15, 2023
    Copy the full SHA
    0c2ade1 View commit details
  4. Copy the full SHA
    aa422f5 View commit details
  5. add Go 1.21 to the build matrix (#392)

    * add Go 1.21 to the build matrix
    
    * drop Go 1.18
    shogo82148 authored Sep 15, 2023
    Copy the full SHA
    c25bb8b View commit details
  6. Copy the full SHA
    c33fec6 View commit details
  7. Copy the full SHA
    0640a15 View commit details
Showing with 326 additions and 64 deletions.
  1. +29 −0 .github/ISSUE_TEMPLATE/bug_report.md
  2. +20 −0 .github/ISSUE_TEMPLATE/feature_request.md
  3. +4 −0 .github/pull_request_template.md
  4. +16 −16 .github/workflows/go.yml
  5. +17 −0 CHANGELOG.md
  6. +12 −0 decode_test.go
  7. +15 −0 encode_test.go
  8. +1 −1 go.mod
  9. +0 −7 parser/context.go
  10. +2 −3 parser/parser.go
  11. +56 −0 parser/parser_test.go
  12. +23 −3 path.go
  13. +7 −0 path_test.go
  14. +2 −2 token/token.go
  15. +3 −0 token/token_test.go
  16. +30 −32 yaml.go
  17. +89 −0 yaml_test.go
29 changes: 29 additions & 0 deletions .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
---
name: Bug report
about: Create a report to help us improve
title: ''
labels: bug
assignees: ''

---

**Describe the bug**
A clear and concise description of what the bug is.

**To Reproduce**

Please provide a minimum yaml content that can be reproduced.
We are more than happy to use [Go Playground](https://go.dev/play)

**Expected behavior**
A clear and concise description of what you expected to happen.

**Screenshots**
If applicable, add screenshots to help explain your problem.

**Version Variables**
- Go version: [e.g. 1.21 ]
- go-yaml's Version: [e.g. v1.11.1 ]

**Additional context**
Add any other context about the problem here.
20 changes: 20 additions & 0 deletions .github/ISSUE_TEMPLATE/feature_request.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
name: Feature request
about: Suggest an idea for this project
title: ''
labels: feature request
assignees: ''

---

**Is your feature request related to a problem? Please describe.**
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]

**Describe the solution you'd like**
A clear and concise description of what you want to happen.

**Describe alternatives you've considered**
A clear and concise description of any alternative solutions or features you've considered.

**Additional context**
Add any other context or screenshots about the feature request here.
4 changes: 4 additions & 0 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Before submitting your PR, please confirm the following.

- [ ] Describe the purpose for which you created this PR.
- [ ] Create test code that corresponds to the modification
32 changes: 16 additions & 16 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
@@ -10,15 +10,15 @@ jobs:
strategy:
matrix:
os: [ "ubuntu-latest", "macos-latest", "windows-latest" ]
go-version: [ "1.18", "1.19", "1.20" ]
go-version: [ "1.19", "1.20", "1.21" ]
runs-on: ${{ matrix.os }}
steps:
- name: checkout
uses: actions/checkout@v4
- name: setup Go ${{ matrix.go-version }}
uses: actions/setup-go@v3
uses: actions/setup-go@v4
with:
go-version: ${{ matrix.go-version }}
- name: checkout
uses: actions/checkout@v3
- name: test
run: |
make test
@@ -28,17 +28,17 @@ jobs:
strategy:
matrix:
os: [ "ubuntu-latest", "windows-latest" ]
go-version: [ "1.18", "1.19", "1.20" ]
go-version: [ "1.19", "1.20", "1.21" ]
runs-on: ${{ matrix.os }}
env:
GOARCH: "386"
steps:
- name: checkout
uses: actions/checkout@v4
- name: setup Go ${{ matrix.go-version }}
uses: actions/setup-go@v3
uses: actions/setup-go@v4
with:
go-version: ${{ matrix.go-version }}
- name: checkout
uses: actions/checkout@v3
- name: test
run: |
make simple-test
@@ -47,12 +47,12 @@ jobs:
name: ycat
runs-on: ubuntu-latest
steps:
- name: checkout
uses: actions/checkout@v4
- name: setup Go
uses: actions/setup-go@v3
uses: actions/setup-go@v4
with:
go-version: "1.20"
- name: checkout
uses: actions/checkout@v3
go-version: "1.21"
- name: build
run: |
make ycat/build
@@ -64,12 +64,12 @@ jobs:
name: Coverage
runs-on: ubuntu-latest
steps:
- name: checkout
uses: actions/checkout@v4
- name: setup Go
uses: actions/setup-go@v3
uses: actions/setup-go@v4
with:
go-version: "1.20"
- name: checkout
uses: actions/checkout@v3
go-version: "1.21"
- name: measure coverage
run: |
make cover
17 changes: 17 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
# 1.11.2 - 2023-09-15

### Fix bugs

- Fix quoted comments ( #370 )
- Fix handle of space at start or last ( #376 )
- Fix sequence with comment ( #390 )

# 1.11.1 - 2023-09-14

### Fix bugs

- Handle `\r` in a double-quoted string the same as `\n` ( #372 )
- Replace loop with n.Values = append(n.Values, target.Values...) ( #380 )
- Skip encoding an inline field if it is null ( #386 )
- Fix comment parsing with null value ( #388 )

# 1.11.0 - 2023-04-03

### Features
12 changes: 12 additions & 0 deletions decode_test.go
Original file line number Diff line number Diff line change
@@ -67,6 +67,18 @@ func TestDecoder(t *testing.T) {
"v: 1.234\n",
map[string]string{"v": "1.234"},
},
{
"v: \" foo\"\n",
map[string]string{"v": " foo"},
},
{
"v: \"foo \"\n",
map[string]string{"v": "foo "},
},
{
"v: \" foo \"\n",
map[string]string{"v": " foo "},
},
{
"v: false\n",
map[string]bool{"v": false},
15 changes: 15 additions & 0 deletions encode_test.go
Original file line number Diff line number Diff line change
@@ -303,6 +303,21 @@ func TestEncoder(t *testing.T) {
map[string]string{"a": "Hello #comment"},
nil,
},
{
"a: \" b\"\n",
map[string]string{"a": " b"},
nil,
},
{
"a: \"b \"\n",
map[string]string{"a": "b "},
nil,
},
{
"a: \" b \"\n",
map[string]string{"a": " b "},
nil,
},
{
"a: 100.5\n",
map[string]interface{}{
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/goccy/go-yaml

go 1.18
go 1.19

require (
github.com/fatih/color v1.10.0
7 changes: 0 additions & 7 deletions parser/context.go
Original file line number Diff line number Diff line change
@@ -13,7 +13,6 @@ type context struct {
idx int
size int
tokens token.Tokens
mode Mode
path string
}

@@ -56,7 +55,6 @@ func (c *context) copy() *context {
idx: c.idx,
size: c.size,
tokens: append(token.Tokens{}, c.tokens...),
mode: c.mode,
path: c.path,
}
}
@@ -145,10 +143,6 @@ func (c *context) afterNextNotCommentToken() *token.Token {
return nil
}

func (c *context) enabledComment() bool {
return c.mode&ParseComments != 0
}

func (c *context) isCurrentCommentToken() bool {
tk := c.currentToken()
if tk == nil {
@@ -193,7 +187,6 @@ func newContext(tokens token.Tokens, mode Mode) *context {
idx: 0,
size: len(filteredTokens),
tokens: token.Tokens(filteredTokens),
mode: mode,
path: "$",
}
}
5 changes: 2 additions & 3 deletions parser/parser.go
Original file line number Diff line number Diff line change
@@ -334,10 +334,9 @@ func (p *parser) parseSequenceEntry(ctx *context) (*ast.SequenceNode, error) {
if tk.Type == token.CommentType {
comment = p.parseCommentOnly(ctx)
tk = ctx.currentToken()
if tk.Type != token.SequenceEntryType {
break
if tk.Type == token.SequenceEntryType {
ctx.progress(1) // skip sequence token
}
ctx.progress(1) // skip sequence token
}
value, err := p.parseToken(ctx.withIndex(uint(len(sequenceNode.Values))), ctx.currentToken())
if err != nil {
56 changes: 56 additions & 0 deletions parser/parser_test.go
Original file line number Diff line number Diff line change
@@ -7,6 +7,7 @@ import (
"strings"
"testing"

"github.com/goccy/go-yaml"
"github.com/goccy/go-yaml/ast"
"github.com/goccy/go-yaml/lexer"
"github.com/goccy/go-yaml/parser"
@@ -873,7 +874,58 @@ baz: 1`
t.Fatal("failed to parse comment")
}
})
}

func TestSequenceComment(t *testing.T) {
content := `
foo:
- # comment
bar: 1
baz:
- xxx
`
f, err := parser.ParseBytes([]byte(content), parser.ParseComments)
if err != nil {
t.Fatal(err)
}
if len(f.Docs) != 1 {
t.Fatal("failed to parse content with next line with sequence")
}
expected := `
foo:
# comment
- bar: 1
baz:
- xxx`
if f.Docs[0].String() != strings.TrimPrefix(expected, "\n") {
t.Fatal("failed to parse comment")
}
t.Run("foo[0].bar", func(t *testing.T) {
path, err := yaml.PathString("$.foo[0].bar")
if err != nil {
t.Fatal(err)
}
v, err := path.FilterFile(f)
if err != nil {
t.Fatal(err)
}
if v.String() != "1" {
t.Fatal("failed to get foo[0].bar value")
}
})
t.Run("baz[0]", func(t *testing.T) {
path, err := yaml.PathString("$.baz[0]")
if err != nil {
t.Fatal(err)
}
v, err := path.FilterFile(f)
if err != nil {
t.Fatal(err)
}
if v.String() != "xxx" {
t.Fatal("failed to get baz[0] value")
}
})
}

func TestNodePath(t *testing.T) {
@@ -892,6 +944,8 @@ a: # commentA
i: fuga # commentI
j: piyo # commentJ
k.l.m.n: moge # commentKLMN
o#p: hogera # commentOP
q#.r: hogehoge # commentQR
`
f, err := parser.ParseBytes([]byte(yml), parser.ParseComments)
if err != nil {
@@ -922,6 +976,8 @@ k.l.m.n: moge # commentKLMN
"$.a.i",
"$.j",
"$.'k.l.m.n'",
"$.o#p",
"$.'q#.r'",
}
if !reflect.DeepEqual(expectedPaths, commentPaths) {
t.Fatalf("failed to get YAMLPath to the comment node:\nexpected[%s]\ngot [%s]", expectedPaths, commentPaths)
26 changes: 23 additions & 3 deletions path.go
Original file line number Diff line number Diff line change
@@ -500,11 +500,29 @@ func newSelectorNode(selector string) *selectorNode {
}

func (n *selectorNode) filter(node ast.Node) (ast.Node, error) {
selector := n.selector
if len(selector) > 1 && selector[0] == '\'' && selector[len(selector)-1] == '\'' {
selector = selector[1 : len(selector)-1]
}
switch node.Type() {
case ast.MappingType:
for _, value := range node.(*ast.MappingNode).Values {
key := value.Key.GetToken().Value
if key == n.selector {
if len(key) > 0 {
switch key[0] {
case '"':
var err error
key, err = strconv.Unquote(key)
if err != nil {
return nil, errors.Wrapf(err, "failed to unquote")
}
case '\'':
if len(key) > 1 && key[len(key)-1] == '\'' {
key = key[1 : len(key)-1]
}
}
}
if key == selector {
if n.child == nil {
return value.Value, nil
}
@@ -518,7 +536,7 @@ func (n *selectorNode) filter(node ast.Node) (ast.Node, error) {
case ast.MappingValueType:
value := node.(*ast.MappingValueNode)
key := value.Key.GetToken().Value
if key == n.selector {
if key == selector {
if n.child == nil {
return value.Value, nil
}
@@ -571,7 +589,9 @@ func (n *selectorNode) replace(node ast.Node, target ast.Node) error {
}

func (n *selectorNode) String() string {
s := fmt.Sprintf(".%s", n.selector)
var builder PathBuilder
selector := builder.normalizeSelectorName(n.selector)
s := fmt.Sprintf(".%s", selector)
if n.child != nil {
s += n.child.String()
}
Loading