Skip to content

Read remaining config files as UTF-8 regardless of locale#4134

Open
lunkwill42 wants to merge 3 commits into
masterfrom
bugfix/config-utf8-readers
Open

Read remaining config files as UTF-8 regardless of locale#4134
lunkwill42 wants to merge 3 commits into
masterfrom
bugfix/config-utf8-readers

Conversation

@lunkwill42

Copy link
Copy Markdown
Member

Scope and purpose

Follow-up to #4132, which #4133 fixed for ipdevpoll.conf on the 5.19.x branch. That crash — a UnicodeDecodeError raised when a config file containing UTF-8 is read under a non-UTF-8 locale such as LANG=C — was never unique to ipdevpoll: several other readers decode config files using the locale's preferred encoding rather than UTF-8, so the same failure can strike any of them. This hardens the remaining readers (arnold, logengine, logs, mailin, and the syslogger web view — plus arnold.parse_nonblock_file, which reads its file with a bare open()) to always decode as UTF-8, matching what open_configfile() already does.

It also adds a test module that walks the shipped etc/ tree asserting every example file is valid UTF-8 and that the INI and TOML examples parse through NAV's own readers, plus a locale-forced regression test proving a configparser-based reader still decodes UTF-8 when the interpreter's preferred encoding is ASCII.

The NAVConfigParser fix and the shipped-config character revert from #4133 reach master via the normal 5.19.x merge-forward and are intentionally not duplicated here.

Contributor Checklist

Every pull request should have this checklist filled out, no matter how small it is.
More information about contributing to NAV can be found in the
Hacker's guide to NAV.

  • Added a changelog fragment for towncrier
  • Added/amended tests for new/changed code
  • Added/changed documentation
  • Linted/formatted the code with ruff, easiest by using pre-commit
  • Wrote the commit message so that the first line continues the sentence "If applied, this commit will ...", starts with a capital letter, does not end with punctuation and is 50 characters or less long. See https://cbea.ms/git-commit/
  • Based this pull request on the correct upstream branch: based on master, as this hardens latent behaviour present across all versions rather than fixing the specific 5.19 regression (Read config files as UTF-8 regardless of locale #4133 handles that on 5.19.x).
  • If applicable: Created new issues if this PR does not fix the issue completely/there is further work to be done
  • If it's not obvious from a linked issue, described how to interact with NAV in order for a reviewer to observe the effects of this change first-hand (commands, URLs, UI interactions)
  • If this results in changes in the UI: Added screenshots of the before and after
  • If this adds a new Python source code file: Added the boilerplate header to that file

Several subsystems read config files with a plain
configparser.ConfigParser (or a bare open()) and did not specify an
encoding, so the file was decoded using the locale's preferred
encoding. Under a non-UTF-8 locale (e.g. LANG=C) that raises
UnicodeDecodeError on any config file containing UTF-8 -- the same
class of bug reported in #4132 for ipdevpoll.conf.

Read these files as UTF-8 too, matching what open_configfile()
already does.

Refs #4132
Add a new test module covering NAV's config file handling: that
every shipped file under etc/ is valid UTF-8, that the shipped INI
and TOML examples parse through NAV's own readers, and that a
configparser-based reader decodes as UTF-8 even when the locale's
preferred encoding is ASCII (a regression test for the raw-reader
fix).

Refs #4132
@lunkwill42 lunkwill42 self-assigned this Jul 10, 2026
@lunkwill42
lunkwill42 requested a review from a team July 10, 2026 11:18
@sonarqubecloud

Copy link
Copy Markdown

@sonarqubecloud

Copy link
Copy Markdown

❌ The last analysis has failed.

See analysis details on SonarQube Cloud

@github-actions

Copy link
Copy Markdown

Test results

    5 files      5 suites   8m 6s ⏱️
3 378 tests 3 378 ✅ 0 💤 0 ❌
6 680 runs  6 680 ✅ 0 💤 0 ❌

Results for commit dd06276.

@codecov

codecov Bot commented Jul 10, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 71.42857% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 65.37%. Comparing base (b1685b2) to head (dd06276).

Files with missing lines Patch % Lines
python/nav/logs.py 50.00% 1 Missing ⚠️
python/nav/web/syslogger/views.py 0.00% 1 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##           master    #4134   +/-   ##
=======================================
  Coverage   65.37%   65.37%           
=======================================
  Files         629      629           
  Lines       47206    47206           
=======================================
  Hits        30861    30861           
  Misses      16345    16345           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant