Skip to content

Test: prove merge_strings crash on nested-dict .strings (stacked on #741)#750

Draft
mokagio wants to merge 1 commit into
foundationfrom
mokagio/rtk-741-merge-strings-crash-test
Draft

Test: prove merge_strings crash on nested-dict .strings (stacked on #741)#750
mokagio wants to merge 1 commit into
foundationfrom
mokagio/rtk-741-merge-strings-crash-test

Conversation

@mokagio

@mokagio mokagio commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

Stacked on #741 (base = foundation), intentionally left failing — this is a review artifact, not a fix. It's here so the change to merge_strings prefixing is decided with the regression in front of us.

The bug it proves

L10nHelper.merge_strings now books keys via plutil (which parses a nested-dictionary value fine) but re-tokenizes the raw lines through StringsFileValidationHelper.prefix_keys, which raises on the {:

RuntimeError: Invalid character `{` found (current context: after_quoted_key_and_eq)

A file like "k" = { a = b; }; is a valid property list, so plutil -lint passes and file reports ASCII textstrings_file_type returns :text. It clears the format gate in merge_strings, reaches prefix_keys, and aborts. Before this PR the line-based gsub never raised — it copied such a line through unprefixed. So a public ios_merge_strings_files run that used to complete now crashes.

This mirrors the fail-soft decision already made on the scanner path (scan_for_duplicate_keys rescues rather than crash the lane); merge_strings didn't get the same treatment.

Suggested resolution (reviewer's call)

Rescue the tokenizer in merge_strings and copy the line verbatim when it can't be prefixed (nested dicts aren't key = value so there's nothing to prefix anyway), or otherwise skip prefixing that file. Then flip this test's assertion to also check the line survives.

Verification

bundle exec rspec spec/ios_l10n_helper_spec.rb -e "nested dictionary" → 1 example, 1 failure (the not_to raise_error above). The rest of the suite is unaffected by this commit.


Opened by Claude (Opus 4.8) on behalf of @mokagio with approval.

`L10nHelper.merge_strings` bookkeeps keys via `plutil` (which parses a
nested-dictionary value fine) but re-tokenizes the raw lines through
`prefix_keys`, which raises `Invalid character` on the `{`.
Such a file is a valid property list, still detected as `:text`, so it
passes the format gate and reaches `prefix_keys` — a public
`ios_merge_strings_files` run that previously copied the line through now
aborts.

This stacks a regression test on top of #741 and is intentionally left
red so the reviewer can decide how to make the path fail-soft (e.g.
rescue and copy the line verbatim, matching the scanner path).

---

Generated with the help of Claude Code, https://claude.com/claude-code

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@mokagio mokagio self-assigned this Jul 1, 2026
@dangermattic

Copy link
Copy Markdown
Collaborator
1 Warning
⚠️ Please add an entry in the CHANGELOG.md file to describe the changes made by this PR
1 Message
📖 This PR is still a Draft: some checks will be skipped.

Generated by 🚫 Danger

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.

2 participants