1
0
Fork 0
mirror of https://github.com/imjasonh/terraform-playground synced 2026-07-18 23:20:18 +00:00

Address Copilot review: require python prefix; robust entry_points parsing

- parsePythonTag now rejects tags without the 'python' prefix (e.g. '3.12'),
  which would otherwise produce a bogus .../lib/3.12/site-packages layout
- parseConsoleScripts iterates with strings.Split instead of bufio.Scanner, so
  a long line/large entry_points.txt can't silently truncate the launcher set
- tests for both

Co-authored-by: Jason Hall <imjasonh@users.noreply.github.com>
This commit is contained in:
Cursor Agent 2026-06-11 00:01:44 +00:00
parent 90030346c6
commit 74982d6dc6
No known key found for this signature in database
4 changed files with 26 additions and 6 deletions

View file

@ -459,9 +459,14 @@ func platformTarget(platform *v1.Platform) wheel.Target {
return t
}
// parsePythonTag parses "python3.12" into (3, 12).
// parsePythonTag parses "python3.12" into (3, 12). The tag must start with
// "python" because it is also used verbatim as the site-packages lib directory
// (".../lib/python3.12/site-packages").
func parsePythonTag(tag string) (int, int, error) {
s := strings.TrimPrefix(tag, "python")
s, ok := strings.CutPrefix(tag, "python")
if !ok {
return 0, 0, fmt.Errorf("--python %q must look like pythonX.Y", tag)
}
majStr, minStr, ok := strings.Cut(s, ".")
if !ok {
return 0, 0, fmt.Errorf("--python %q must look like pythonX.Y", tag)

View file

@ -440,6 +440,10 @@ func TestParsePythonTag(t *testing.T) {
if _, _, err := parsePythonTag("python3"); err == nil {
t.Error("expected error for missing minor version")
}
// Must require the "python" prefix (it's also the site-packages lib dir).
if _, _, err := parsePythonTag("3.12"); err == nil {
t.Error("expected error for tag without 'python' prefix")
}
}
func TestPlatformTargetDefaults(t *testing.T) {

View file

@ -14,7 +14,6 @@ package wheel
import (
"archive/zip"
"bufio"
"fmt"
"io"
"path"
@ -360,9 +359,10 @@ type entryPoint struct{ module, attr string }
func parseConsoleScripts(s string) map[string]entryPoint {
out := map[string]entryPoint{}
section := ""
sc := bufio.NewScanner(strings.NewReader(s))
for sc.Scan() {
line := strings.TrimSpace(sc.Text())
// The file is already fully in memory, so split directly rather than using a
// bufio.Scanner (whose default token limit would silently drop long lines).
for _, raw := range strings.Split(s, "\n") {
line := strings.TrimSpace(raw)
if line == "" || strings.HasPrefix(line, "#") {
continue
}

View file

@ -196,6 +196,17 @@ func TestConsoleScriptExtrasStripped(t *testing.T) {
}
}
func TestParseConsoleScriptsLongLineNotTruncated(t *testing.T) {
// A comment line longer than bufio.Scanner's default 64 KiB token limit
// would have made a Scanner stop early and silently drop later entries.
longComment := "# " + strings.Repeat("x", 200*1024)
content := longComment + "\n[console_scripts]\ntool = pkg.mod:main\n"
eps := parseConsoleScripts(content)
if ep, ok := eps["tool"]; !ok || ep.module != "pkg.mod" || ep.attr != "main" {
t.Fatalf("entry after a very long line was dropped: %+v", eps)
}
}
func TestFilesDeterministic(t *testing.T) {
path := writeFixture(t)
digest := func() string {