From cd38d72b41720693d6b595b6c1510a5c4618d36a Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 12 Aug 2026 03:22:53 +0000 Subject: [PATCH 1/3] Initial plan From 0a39cac62f65655ff17380daf61e77c71da9eaf0 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 12 Aug 2026 03:30:10 +0000 Subject: [PATCH 2/3] Refactor nested YAML value extraction Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com> --- pkg/parser/schema_suggestions.go | 37 +++++++++++++-------------- pkg/parser/schema_suggestions_test.go | 6 +++++ 2 files changed, 24 insertions(+), 19 deletions(-) diff --git a/pkg/parser/schema_suggestions.go b/pkg/parser/schema_suggestions.go index a08011239eb..82edcc26e49 100644 --- a/pkg/parser/schema_suggestions.go +++ b/pkg/parser/schema_suggestions.go @@ -581,30 +581,29 @@ func extractNestedYAMLValue(yamlContent, parentKey, childKey string) string { continue } - // Try to match child key with its value (single-quoted, double-quoted, unquoted). - childPrefix := `^\s+` + escapedChild + `[ \t]*:[ \t]*` - //nolint:regexpdynamicpattern // The child key is quoted before compilation. - reSingle, err := regexp.Compile(childPrefix + `'([^'\n]+)'`) - if err != nil { - return "" - } - if match := reSingle.FindStringSubmatch(line); len(match) >= 2 { - return strings.TrimSpace(match[1]) - } - //nolint:regexpdynamicpattern // The child key is quoted before compilation. - reDouble, err := regexp.Compile(childPrefix + `"([^"\n]+)"`) - if err != nil { - return "" - } - if match := reDouble.FindStringSubmatch(line); len(match) >= 2 { - return strings.TrimSpace(match[1]) + if value := extractNestedYAMLScalar(line, escapedChild); value != "" { + return value } + } + + return "" +} + +func extractNestedYAMLScalar(line, escapedChild string) string { + childPrefix := `^\s+` + escapedChild + `[ \t]*:[ \t]*` + valuePatterns := []string{ + childPrefix + `'([^'\n]+)'`, + childPrefix + `"([^"\n]+)"`, + childPrefix + `([^'"\n#][^\n#]*?)(?:[ \t]*#.*)?$`, + } + + for _, valuePattern := range valuePatterns { //nolint:regexpdynamicpattern // The child key is quoted before compilation. - reUnquoted, err := regexp.Compile(childPrefix + `([^'"\n#][^\n#]*?)(?:[ \t]*#.*)?$`) + valueRegexp, err := regexp.Compile(valuePattern) if err != nil { return "" } - if match := reUnquoted.FindStringSubmatch(line); len(match) >= 2 { + if match := valueRegexp.FindStringSubmatch(line); len(match) >= 2 { return strings.TrimSpace(match[1]) } } diff --git a/pkg/parser/schema_suggestions_test.go b/pkg/parser/schema_suggestions_test.go index fee361573dc..b5c08fa45b2 100644 --- a/pkg/parser/schema_suggestions_test.go +++ b/pkg/parser/schema_suggestions_test.go @@ -405,6 +405,12 @@ func TestExtractYAMLValueAtPath(t *testing.T) { path: "/permissions/contents", wantValue: "raed", }, + { + name: "nested path - unquoted value with inline comment", + yaml: "permissions:\n contents: raed # typo\n", + path: "/permissions/contents", + wantValue: "raed", + }, { name: "three-level path returns empty", yaml: "a:\n b:\n c: value\n", From 9f60a7acd61dc70e97308f86fd9e75bdf27bb762 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 13 Aug 2026 18:55:04 +0000 Subject: [PATCH 3/3] Compile nested YAML scalar matchers once per scan Co-authored-by: gh-aw-bot <259018956+gh-aw-bot@users.noreply.github.com> --- pkg/parser/schema_suggestions.go | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/pkg/parser/schema_suggestions.go b/pkg/parser/schema_suggestions.go index 82edcc26e49..c4e2b512daa 100644 --- a/pkg/parser/schema_suggestions.go +++ b/pkg/parser/schema_suggestions.go @@ -545,7 +545,10 @@ func extractNestedYAMLValue(yamlContent, parentKey, childKey string) string { if err != nil { return "" } - escapedChild := regexp.QuoteMeta(childKey) + scalarMatchers, err := buildNestedYAMLScalarMatchers(regexp.QuoteMeta(childKey)) + if err != nil { + return "" + } parentIndent := -1 childIndent := -1 // indent of direct children (set on first non-blank line inside the block) @@ -581,7 +584,7 @@ func extractNestedYAMLValue(yamlContent, parentKey, childKey string) string { continue } - if value := extractNestedYAMLScalar(line, escapedChild); value != "" { + if value := extractNestedYAMLScalar(line, scalarMatchers); value != "" { return value } } @@ -589,7 +592,9 @@ func extractNestedYAMLValue(yamlContent, parentKey, childKey string) string { return "" } -func extractNestedYAMLScalar(line, escapedChild string) string { +// buildNestedYAMLScalarMatchers compiles the scalar value patterns for a child key once, +// so they can be reused across every candidate line inside the parent block. +func buildNestedYAMLScalarMatchers(escapedChild string) ([]*regexp.Regexp, error) { childPrefix := `^\s+` + escapedChild + `[ \t]*:[ \t]*` valuePatterns := []string{ childPrefix + `'([^'\n]+)'`, @@ -597,12 +602,21 @@ func extractNestedYAMLScalar(line, escapedChild string) string { childPrefix + `([^'"\n#][^\n#]*?)(?:[ \t]*#.*)?$`, } + matchers := make([]*regexp.Regexp, 0, len(valuePatterns)) for _, valuePattern := range valuePatterns { //nolint:regexpdynamicpattern // The child key is quoted before compilation. valueRegexp, err := regexp.Compile(valuePattern) if err != nil { - return "" + return nil, err } + matchers = append(matchers, valueRegexp) + } + + return matchers, nil +} + +func extractNestedYAMLScalar(line string, matchers []*regexp.Regexp) string { + for _, valueRegexp := range matchers { if match := valueRegexp.FindStringSubmatch(line); len(match) >= 2 { return strings.TrimSpace(match[1]) }