Skip to content

configure.sh's Ruleset Name Lookup Can Carry the Same Windows CRLF #1123 Fixed in Settings #1234

Closed

Description

@ptr727

Summary

repo-config/configure.sh resolves a ruleset payload's declared name with jq -r '.name // empty' "$file", at both apply_ruleset() (line 144) and check_ruleset() (line 253). On a native Windows jq (the same WinGet jq-1.8.2 behavior #1123 and its fix in PR #1229 document: unconditional CRLF on stdout), that command substitution would carry a trailing \r into $rname the same way it did into configure.sh check's settings comparison.

$rname then feeds ruleset_id()'s lookup:

ids="$(jq -r --arg n "$1" '.[] | select(.name==$n) | .id' <<<"$out")"

where $out is a gh api JSON body (never passed through a local jq -r, so it stays \r-free). A \r-suffixed $rname (e.g. "main\r") never matches a clean live .name ("main"), so ruleset_id() reports "not found" for a ruleset that exists.

Impact

  • check mode: check_ruleset() reports the ruleset as missing (fail "ruleset '$rname' missing") even when it is present and correctly configured, the same class of false-drift repo-config/configure.sh check reports every setting but the last as drifted on Windows, because jq emits CRLF #1123 fixed for static settings.
  • apply mode: apply_ruleset() takes the same "not found" path as create-vs-update, so gh api --method POST "repos/$repo/rulesets" runs instead of a PUT to the existing ruleset. Run repeatedly (or with more than one ruleset payload), this could create duplicate rulesets by name rather than update the existing one, a state-changing consequence, not just a reporting artifact.

Suggested fix

Route rname="$(jq -r '.name // empty' "$file")" (both call sites) through the same CR-stripping technique #1123 uses for check_settings() (repo-config/configure.sh's jqr() helper as of PR #1229), since $file is read from a local ruleset payload, not from $out, so it is exactly the asymmetric one-side-jq-derived shape #1123 describes.

Context

Found while implementing #1194 and #1123 together in PR #1229: fixing #1123's check_settings() comparisons surfaced this sibling defect in ruleset_id()/apply_ruleset()/check_ruleset(), a different function with a wider blast radius (an apply-mode state change, not just a check-mode false report). Filed rather than folded into #1229 to keep that PR scoped to what #1194 and #1123 actually cover.

Unverified on a real Windows host, same as #1123 itself; the reasoning follows from jq's own documented native-Windows CRLF stdout behavior (unconditional unless -b/--binary is passed).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions