Skip to content

[medium] fix: [brctl] container values containing a space are silently truncated to their first word - #253

Open
elhoim wants to merge 1 commit into
EC-DIGIT-CSIRC:mainfrom
elhoim:fix/brctl-value-truncation
Open

[medium] fix: [brctl] container values containing a space are silently truncated to their first word#253
elhoim wants to merge 1 commit into
EC-DIGIT-CSIRC:mainfrom
elhoim:fix/brctl-value-truncation

Conversation

@elhoim

@elhoim elhoim commented Sep 5, 2026

Copy link
Copy Markdown
Contributor

BLUF

  • Priority: medium. BrctlParser.parselistfile() matches container values with ([^ \[]+|\[[^\]]*\]), which stops at the first space. Real brctl-container-list.txt values are single-quoted and routinely contain spaces, so they are silently truncated.
  • Confirmed against the project's own iOS 16 test archive, not hypothetically. localizedName:'iCloud Drive' is parsed as 'iCloud. clients: com.apple.passd, com.apple.PassbookUIService, com.apple.Passbook is parsed as com.apple.passd, — two of the three clients are dropped, and a trailing comma is kept.
  • Every value also retains its surrounding quotes ("localizedName": "'Wallet'"), because .strip("[]") does not strip '.
  • The Mobile DocumentsMobile_Documents substitution is a workaround for this same bug — a targeted patch for the one path that was noticed. It only ever covered that single literal; any other space-bearing value was left broken.
  • Fix: match quoted values as a unit, strip the quotes, and read clients to the end of the line. The Mobile_Documents round-trip is then unnecessary and is removed.
  • Scope: one method in brctl.py, plus a regression test built from real sample lines.

Before / after, on the iOS 16 test archive

field main this PR
localizedName 'Wallet' Wallet
localizedName (CloudDocs) 'iCloud iCloud Drive
clients com.apple.passd, com.apple.passd, com.apple.PassbookUIService, com.apple.Passbook
documents correct (via the hack) correct (structurally)

The fix

CONTAINER_KEYS = ("id", "localizedName", "documents", "Public", "Private", "clients")
CONTAINER_VALUE_RE = re.compile(rf"({'|'.join(CONTAINER_KEYS)}):\s*('[^']*'|\[[^\]]*\]|[^ \[]*)")
CONTAINER_CLIENTS_RE = re.compile(r"clients:\s*(.*)$")

Three value shapes are matched explicitly — single-quoted (may contain spaces), bracketed, bare token — and clients is taken to the end of the line because it is both space- and comma-separated.

Note on the output schema

localizedName and documents no longer carry surrounding ' characters, and clients now holds the full list rather than its first entry. Both are corrections of truncated/garbled values rather than new fields, but they do change the emitted strings, so this is worth a deliberate look during review.

Test

test_parselistfile_keeps_values_containing_spaces uses two verbatim lines from the iOS 16 archive and asserts the space-bearing localizedName, the full documents path, and the complete clients list.

Verified to fail on main with AssertionError: 'Wallet' != "'Wallet'" and pass with this change. The existing test_parsebrctl is unaffected.

…he first space

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@elhoim
elhoim force-pushed the fix/brctl-value-truncation branch from 8f4d3df to 95c6ca4 Compare September 9, 2026 07:30
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