|
| 1 | +package parser |
| 2 | + |
| 3 | +import ( |
| 4 | + "testing" |
| 5 | +) |
| 6 | + |
| 7 | +func TestParseTOMLUnquotesKeys(t *testing.T) { |
| 8 | + // `.cherry_picker.toml` in apache/airflow has `"check_sha" = "..."` — |
| 9 | + // a quoted top-level key. Pre-fix the key string included the literal |
| 10 | + // quotes which propagated into node IDs like |
| 11 | + // `toml:.cherry_picker.toml:"check_sha"`, and CONTAINS edges then |
| 12 | + // referenced PKs that the bulk-load couldn't resolve. |
| 13 | + src := []byte(`team = "apache" |
| 14 | +repo = "airflow" |
| 15 | +"check_sha" = "abc123" |
| 16 | +'literal_key' = "single-quoted" |
| 17 | +`) |
| 18 | + env := parseTOML(src) |
| 19 | + data, ok := env["data"].(map[string]any) |
| 20 | + if !ok { |
| 21 | + t.Fatalf("envelope missing data map: %#v", env) |
| 22 | + } |
| 23 | + for k, want := range map[string]string{ |
| 24 | + "team": "apache", |
| 25 | + "repo": "airflow", |
| 26 | + "check_sha": "abc123", |
| 27 | + "literal_key": "single-quoted", |
| 28 | + } { |
| 29 | + got, ok := data[k].(string) |
| 30 | + if !ok { |
| 31 | + t.Errorf("key %q missing or non-string: %#v", k, data[k]) |
| 32 | + continue |
| 33 | + } |
| 34 | + if got != want { |
| 35 | + t.Errorf("data[%q] = %q, want %q", k, got, want) |
| 36 | + } |
| 37 | + } |
| 38 | + // Negative: a quoted form must NOT appear as its own key. |
| 39 | + for _, badKey := range []string{`"check_sha"`, `'literal_key'`} { |
| 40 | + if _, exists := data[badKey]; exists { |
| 41 | + t.Errorf("data still has quote-bearing key %q — unquote not applied", badKey) |
| 42 | + } |
| 43 | + } |
| 44 | +} |
| 45 | + |
| 46 | +func TestParseTOMLUnquotesSectionHeaders(t *testing.T) { |
| 47 | + // Less common in practice, but TOML spec allows `["foo.bar"]` quoted |
| 48 | + // section headers. Same fix applies — unquote before using as map key. |
| 49 | + src := []byte(`["quoted-section"] |
| 50 | +inner = "v" |
| 51 | +`) |
| 52 | + env := parseTOML(src) |
| 53 | + data := env["data"].(map[string]any) |
| 54 | + if _, ok := data["quoted-section"]; !ok { |
| 55 | + t.Errorf("missing top-level section 'quoted-section': %#v", data) |
| 56 | + } |
| 57 | + if _, ok := data[`"quoted-section"`]; ok { |
| 58 | + t.Errorf("section header retained literal quotes — unquote not applied") |
| 59 | + } |
| 60 | +} |
0 commit comments