diff --git a/yq.go b/yq.go index 06838189..c2eb92e0 100644 --- a/yq.go +++ b/yq.go @@ -181,7 +181,7 @@ func readProperty(cmd *cobra.Command, args []string) error { return nil } -var regexpSubdocPath = regexp.MustCompile(`^@(\d+)\.(.*)$`) +var regexpSubdocPath = regexp.MustCompile(`^@(\d+)(?:\.)?(.*)?$`) func read(args []string) (interface{}, error) { var ( diff --git a/yq_test.go b/yq_test.go index b2b764f9..704eb999 100644 --- a/yq_test.go +++ b/yq_test.go @@ -43,7 +43,15 @@ func TestReadMultipleDocuments(t *testing.T) { result, _ := read([]string{"examples/multidocument.yaml", "b.c"}) assertResult(t, 1, result) }) - t.Run("multiple documents with leading @n reads from document n", func(t *testing.T) { + t.Run("multiple documents with @n path reads document n", func(t *testing.T) { + result, _ := read([]string{"examples/multidocument.yaml", "@0"}) + actual, err := yamlToString(result) + assertNilErr(t, err) + assertResult(t, `a: Document One +b: + c: 1`, actual) + }) + t.Run("multiple documents with leading @n path reads path from document n", func(t *testing.T) { result, _ := read([]string{"examples/multidocument.yaml", "@0.b.c"}) assertResult(t, 1, result)