Repository navigation
contrib/awk: add GNU parity coverage and sandbox I/O - #769
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 0ccec7c8fd
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| p.fieldSep = p.toString(v) | ||
| if utf8.RuneCountInString(p.fieldSep) > 1 { // compare to interp.ensureFields | ||
| re, err := regexp.Compile(compiler.AddRegexFlags(p.fieldSep)) | ||
| re, err := p.compileRegex(p.fieldSep) | ||
| if err != nil { | ||
| return newError("invalid regex %q: %s", p.fieldSep, err) | ||
| return err |
There was a problem hiding this comment.
Reset field splitting mode when FS is assigned
After FIELDWIDTHS or FPAT has been set, assigning FS should switch record splitting back to FS-based behavior (matching gawk), but this branch only updates fieldSep/fieldSepRegex and never clears the alternative split modes. Because ensureFields() checks fieldWidths and fieldPatternRegex first, scripts that change split mode at runtime keep using stale FIELDWIDTHS/FPAT rules and produce incorrect fields.
Useful? React with 👍 / 👎.
| if len(rest) > 0 && rest[0] != 0 { | ||
| loc = time.UTC | ||
| } | ||
| t := time.Date(values[0], time.Month(values[1]), values[2], values[3], values[4], values[5], 0, loc) |
There was a problem hiding this comment.
Honor the DST component in mktime datespec
The 7th mktime datespec field is parsed into values[6] but never applied when constructing the timestamp. GNU awk uses this field to force DST/non-DST interpretation, so around DST boundaries this implementation returns the wrong epoch (for example, forcing DST=0 in a summer timestamp should differ by one hour in zones like America/New_York).
Useful? React with 👍 / 👎.
| target := "" | ||
| if len(rest) > 0 { | ||
| target = rest[0] | ||
| } |
There was a problem hiding this comment.
Default gensub target to current record when arg is omitted
With GNU awk, calling gensub(regex, repl, how) (3 args) applies substitutions to $0. Here the target defaults to an empty string unless a 4th argument is present, so 3-argument calls silently operate on "" and return incorrect results instead of transforming the current record.
Useful? React with 👍 / 👎.
What changed
This updates
contrib/awktoward GNU awk parity inside the gbash sandbox.-f,-e,-E,-i, long options, and GNU info outputsystem(),cmd | getline, andprint | cmdthrough sandbox-ownedInvocation.FSand nestedInvocation.Exechooks instead of host-global file or process APIsgensub,strtonum,systime,mktime,strftime, bitwise builtins,ARGIND,PROCINFO["version"],IGNORECASE,FIELDWIDTHS, andFPATSPEC.mdWhy
The previous awk adapter intentionally disabled shell execution, redirected output, and non-input-file reads, so it diverged from GNU awk in exactly the areas users expect to work for real programs. The vendored interpreter also lacked the GNU-specific runtime hooks and variable behavior needed to make those features work safely inside gbash.
This change keeps the sandbox boundary intact while making awk behave like GNU awk within that boundary.
Impact
system()and pipe operators without escaping the gbash runtimeValidation
go test ./contrib/awk/...GBASH_CONFORMANCE_AWK=$(./scripts/ensure-awk.sh) GBASH_CONFORMANCE_BASH=$(./scripts/ensure-bash.sh) GBASH_RUN_AWK_CONFORMANCE=1 go test ./contrib/awk -run 'TestAWKConformance$' -count=1make lint