diff --git a/cmd/cue/cmd/testdata/script/def_jsonschema.txtar b/cmd/cue/cmd/testdata/script/def_jsonschema.txtar index 2987a433b1c..1451d2ac597 100644 --- a/cmd/cue/cmd/testdata/script/def_jsonschema.txtar +++ b/cmd/cue/cmd/testdata/script/def_jsonschema.txtar @@ -73,10 +73,10 @@ age: twenty -- expect-stderr2 -- age: conflicting values "twenty" and int (mismatched types string and int): - ./data.yaml:1:7 + ./data.yaml:1:6 ./schema.json:18:7 -- expect-stderr3 -- age: conflicting values "twenty" and int (mismatched types string and int): - ./data.yaml:1:7 + ./data.yaml:1:6 ./schema.json:18:7 -- cue.mod -- diff --git a/cmd/cue/cmd/testdata/script/issue826.txtar b/cmd/cue/cmd/testdata/script/issue826.txtar new file mode 100644 index 00000000000..87fd1a483c6 --- /dev/null +++ b/cmd/cue/cmd/testdata/script/issue826.txtar @@ -0,0 +1,18 @@ +exec cue import x.yaml +cmp x.cue expect.cue + +-- x.yaml -- +# Importing YAML with multi-byte characters as CUE resulted in bad formatting +# since the YAML decoder would count columns by characters and we count by bytes. +x1: + # ああああああああああああああああああ + description: ああ + type: string +-- expect.cue -- +// Importing YAML with multi-byte characters as CUE resulted in bad formatting +// since the YAML decoder would count columns by characters and we count by bytes. +x1: { + // ああああああああああああああああああ + description: "ああ" + type: "string" +} diff --git a/cmd/cue/cmd/testdata/script/vet_data.txtar b/cmd/cue/cmd/testdata/script/vet_data.txtar index 59e1d64ca01..0f8f9b1ad7d 100644 --- a/cmd/cue/cmd/testdata/script/vet_data.txtar +++ b/cmd/cue/cmd/testdata/script/vet_data.txtar @@ -23,8 +23,8 @@ languages: -- vet-stderr -- languages.1.name: invalid value "dutch" (out of bound =~"^\\p{Lu}"): ./schema.cue:3:8 - ./data.yaml:5:12 + ./data.yaml:5:11 -- export-stderr -- languages.1.name: invalid value "dutch" (out of bound =~"^\\p{Lu}"): ./schema.cue:3:8 - ./data.yaml:5:12 + ./data.yaml:5:11 diff --git a/cmd/cue/cmd/testdata/script/vet_embed.txtar b/cmd/cue/cmd/testdata/script/vet_embed.txtar index f1af948b349..21c66ea87b5 100644 --- a/cmd/cue/cmd/testdata/script/vet_embed.txtar +++ b/cmd/cue/cmd/testdata/script/vet_embed.txtar @@ -32,7 +32,7 @@ e: 2 -- expect-foo -- c: field not allowed: - ./foo.yaml:2:2 + ./foo.yaml:2:1 ./schema.cue:1:1 ./schema.cue:3:7 ./schema.cue:7:1 @@ -41,10 +41,10 @@ d: field not allowed: ./schema.cue:1:1 ./schema.cue:3:7 ./schema.cue:7:1 - ./stream.yaml:2:2 + ./stream.yaml:2:1 -- expect-stream -- d: field not allowed: ./schema.cue:1:1 ./schema.cue:3:7 ./schema.cue:7:1 - ./stream.yaml:2:2 + ./stream.yaml:2:1 diff --git a/doc/tutorial/basics/0_intro/47_validation.txtar b/doc/tutorial/basics/0_intro/47_validation.txtar index 51ac27496c4..6a8e23cec26 100644 --- a/doc/tutorial/basics/0_intro/47_validation.txtar +++ b/doc/tutorial/basics/0_intro/47_validation.txtar @@ -28,4 +28,4 @@ languages: -- expect-stderr -- languages.1.name: invalid value "dutch" (out of bound =~"^\\p{Lu}"): ./schema.cue:3:8 - ./data.yaml:5:12 + ./data.yaml:5:11 diff --git a/doc/tutorial/kubernetes/quick/services/infra/etcd/kube.cue b/doc/tutorial/kubernetes/quick/services/infra/etcd/kube.cue index ae2f756219c..98d713927c3 100644 --- a/doc/tutorial/kubernetes/quick/services/infra/etcd/kube.cue +++ b/doc/tutorial/kubernetes/quick/services/infra/etcd/kube.cue @@ -20,9 +20,7 @@ statefulSet: etcd: spec: { labelSelector: matchExpressions: [{ key: "app" operator: "In" - values: [ - "etcd", - ] + values: ["etcd"] }] topologyKey: "kubernetes.io/hostname" }] diff --git a/doc/tutorial/kubernetes/quick/services/infra/events/kube.cue b/doc/tutorial/kubernetes/quick/services/infra/events/kube.cue index 5299170469b..645d32e045c 100644 --- a/doc/tutorial/kubernetes/quick/services/infra/events/kube.cue +++ b/doc/tutorial/kubernetes/quick/services/infra/events/kube.cue @@ -15,9 +15,7 @@ deployment: events: spec: { labelSelector: matchExpressions: [{ key: "app" operator: "In" - values: [ - "events", - ] + values: ["events"] }] topologyKey: "kubernetes.io/hostname" }] diff --git a/doc/tutorial/kubernetes/quick/services/mon/prometheus/configmap.cue b/doc/tutorial/kubernetes/quick/services/mon/prometheus/configmap.cue index 835d787216f..1b9167afe6c 100644 --- a/doc/tutorial/kubernetes/quick/services/mon/prometheus/configmap.cue +++ b/doc/tutorial/kubernetes/quick/services/mon/prometheus/configmap.cue @@ -51,15 +51,11 @@ configMap: prometheus: { "prometheus.yml": yaml656e63.Marshal(_cue_prometheus_yml) let _cue_prometheus_yml = { global: scrape_interval: "15s" - rule_files: [ - "/etc/prometheus/alert.rules", - ] + rule_files: ["/etc/prometheus/alert.rules"] alerting: alertmanagers: [{ scheme: "http" static_configs: [{ - targets: [ - "alertmanager:9093", - ] + targets: ["alertmanager:9093"] }] }] scrape_configs: [{ diff --git a/internal/third_party/yaml/decode.go b/internal/third_party/yaml/decode.go index f345424c751..c848c41e936 100644 --- a/internal/third_party/yaml/decode.go +++ b/internal/third_party/yaml/decode.go @@ -236,6 +236,8 @@ func (p *parser) sequence() *node { } if len(n.children) > 0 { n.endPos = n.children[len(n.children)-1].endPos + } else { + n.endPos = p.event.start_mark } p.expect(yaml_SEQUENCE_END_EVENT) return n @@ -362,7 +364,7 @@ func (d *decoder) attachLineComment(m yaml_mark_t, pos int8, expr ast.Node) { } func (d *decoder) pos(m yaml_mark_t) token.Pos { - pos := d.p.info.Pos(m.index+1, token.NoRelPos) + pos := d.absPos(m) if d.forceNewline { d.forceNewline = false @@ -390,7 +392,7 @@ func (d *decoder) pos(m yaml_mark_t) token.Pos { } func (d *decoder) absPos(m yaml_mark_t) token.Pos { - return d.p.info.Pos(m.index+1, token.NoRelPos) + return d.p.info.Pos(m.index, token.NoRelPos) } func (d *decoder) start(n *node) token.Pos { diff --git a/internal/third_party/yaml/scannerc.go b/internal/third_party/yaml/scannerc.go index 831a5c64000..fb0d95d7f26 100644 --- a/internal/third_party/yaml/scannerc.go +++ b/internal/third_party/yaml/scannerc.go @@ -489,10 +489,11 @@ func cache(parser *yaml_parser_t, length int) bool { // Advance the buffer pointer. func skip(parser *yaml_parser_t) { - parser.mark.index++ + w := width(parser.buffer[parser.buffer_pos]) + parser.mark.index += w parser.mark.column++ parser.unread-- - parser.buffer_pos += width(parser.buffer[parser.buffer_pos]) + parser.buffer_pos += w } func skip_line(parser *yaml_parser_t) { @@ -503,11 +504,12 @@ func skip_line(parser *yaml_parser_t) { parser.unread -= 2 parser.buffer_pos += 2 } else if is_break(parser.buffer, parser.buffer_pos) { - parser.mark.index++ + w := width(parser.buffer[parser.buffer_pos]) + parser.mark.index += w parser.mark.column = 0 parser.mark.line++ parser.unread-- - parser.buffer_pos += width(parser.buffer[parser.buffer_pos]) + parser.buffer_pos += w } } @@ -528,7 +530,7 @@ func read(parser *yaml_parser_t, s []byte) []byte { s = append(s, parser.buffer[parser.buffer_pos:parser.buffer_pos+w]...) parser.buffer_pos += w } - parser.mark.index++ + parser.mark.index += w parser.mark.column++ parser.unread-- return s diff --git a/pkg/encoding/yaml/testdata/gen.txtar b/pkg/encoding/yaml/testdata/gen.txtar index 7dca2b88799..8a25fafc160 100644 --- a/pkg/encoding/yaml/testdata/gen.txtar +++ b/pkg/encoding/yaml/testdata/gen.txtar @@ -32,14 +32,14 @@ Errors: t1: error in call to encoding/yaml.Validate: invalid value 4 (out of bound <3): ./in.cue:3:5 ./in.cue:3:49 - yaml.Validate:3:5 + yaml.Validate:3:4 t3: error in call to encoding/yaml.Validate: incomplete value int: ./in.cue:5:5 ./in.cue:5:56 t4: error in call to encoding/yaml.ValidatePartial: invalid value 4 (out of bound <3): ./in.cue:6:5 ./in.cue:6:49 - yaml.ValidatePartial:3:5 + yaml.ValidatePartial:3:4 Result: t1: _|_ // t1: error in call to encoding/yaml.Validate: a: invalid value 4 (out of bound <3)