From 1be322b71ef7ff19cff6e35551c1a1cc240ca52d Mon Sep 17 00:00:00 2001 From: "Danilo M." Date: Sat, 13 Jun 2026 18:26:19 +0200 Subject: fix: quote nvchecker section names containing non-bare-key chars Section names with '.', '-', etc. must be TOML-quoted (e.g. ["yt-dlp"]), otherwise nvchecker fails to parse them. add_nvchecker_section wrote bare [pkg] headers, so such names had to be hand-quoted. Worse, _has_nvchecker_section only matched the bare form, so already-present quoted sections were reported as missing and re-flagged for populate on every 'mkhint -C' run. Add _nvchecker_label helper as the single source of truth for the written label (bare iff name matches ^[A-Za-z0-9_]+$, else double-quoted), used by both the write side (3 section headers + messages) and the read side (_has_nvchecker_section grep, with regex metachars escaped so '.' is literal). Tests T32-T34 cover quoted-header write, no-duplicate on re---new, and --check recognizing an existing quoted section. Co-Authored-By: Claude Opus 4.8 --- mkhint | 31 ++++++++++++++++++++++++------- 1 file changed, 24 insertions(+), 7 deletions(-) (limited to 'mkhint') diff --git a/mkhint b/mkhint index e266609..05094e9 100755 --- a/mkhint +++ b/mkhint @@ -261,11 +261,26 @@ EOF fi } -# Return 0 if NVCHECKER_CONFIG already has a [pkg] section +# Emit the TOML section label for a package: bare if the name is a valid +# bare key ([A-Za-z0-9_] only), otherwise double-quoted. nvchecker (and TOML) +# require quoting for names containing '.', '-', etc. +_nvchecker_label() { + local pkg="$1" + if [[ "$pkg" =~ ^[A-Za-z0-9_]+$ ]]; then + printf '[%s]' "$pkg" + else + printf '["%s"]' "$pkg" + fi +} + +# Return 0 if NVCHECKER_CONFIG already has a section for pkg (bare or quoted) _has_nvchecker_section() { local pkg="$1" [[ -f "$NVCHECKER_CONFIG" ]] || return 1 - grep -qE "^\[${pkg}\][[:space:]]*$" "$NVCHECKER_CONFIG" + local label; label=$(_nvchecker_label "$pkg") + # fixed-string match of the exact label at line start, trailing space allowed + grep -qE "^$(printf '%s' "$label" | sed 's/[][\.*^$/]/\\&/g')[[:space:]]*$" \ + "$NVCHECKER_CONFIG" } # Append an nvchecker [pkg] section to NVCHECKER_CONFIG, auto-detecting the @@ -278,9 +293,11 @@ add_nvchecker_section() { mkdir -p "$(dirname "$NVCHECKER_CONFIG")" touch "$NVCHECKER_CONFIG" + local label; label=$(_nvchecker_label "$pkg") + # Skip if section already present if _has_nvchecker_section "$pkg"; then - echo "nvchecker: [${pkg}] already present in $NVCHECKER_CONFIG" + echo "nvchecker: ${label} already present in $NVCHECKER_CONFIG" return 0 fi @@ -298,7 +315,7 @@ add_nvchecker_section() { repo="${repo%.git}" section=$(cat <> "$NVCHECKER_CONFIG" - echo "nvchecker: review/fill [${pkg}] section in $NVCHECKER_CONFIG" + echo "nvchecker: review/fill ${label} section in $NVCHECKER_CONFIG" } # Add NODOWNLOAD=yes after MD5SUM_x86_64 line if not already present -- cgit v1.2.3