Skip to content

fix: support arbitrary whitespace in _forgit_parse_array#541

Open
carlfriedrich wants to merge 1 commit into
wfxr:mainfrom
carlfriedrich:ignore-whitespace-on-parse-array
Open

fix: support arbitrary whitespace in _forgit_parse_array#541
carlfriedrich wants to merge 1 commit into
wfxr:mainfrom
carlfriedrich:ignore-whitespace-on-parse-array

Conversation

@carlfriedrich

@carlfriedrich carlfriedrich commented Jun 22, 2026

Copy link
Copy Markdown
Collaborator

Config variable values spanning multiple lines were silently dropped: read stopped at the first newline and IFS only split on spaces, so the resulting array came out empty.

Example:

export FORGIT_WORKTREE_DELETE_GIT_OPTS="
    --force
"

This resulted in an empty options array before. This PR fixes this and also adds corresponding unit tests (failing before the fix, now green).

Check list

  • I have performed a self-review of my code
  • I have commented my code in hard-to-understand areas
  • I have added unit tests for my code
  • I have made corresponding changes to the documentation

Description

Type of change

  • Bug fix
  • New feature
  • Refactor
  • Breaking change
  • Test
  • Documentation change
  • CI change

Test environment

  • Shell
    • bash
    • zsh
    • fish
  • OS
    • Linux
    • Mac OS X
    • Windows
    • Others:

Summary by CodeRabbit

  • Bug Fixes

    • Enhanced input parsing to correctly handle multiple types of whitespace characters (spaces, tabs, and newlines) when processing command arguments.
  • Tests

    • Introduced comprehensive test coverage for the parsing functionality, including edge cases such as empty inputs, multi-line values, and whitespace-only strings.

Values spanning multiple lines (e.g. a multi-line FORGIT_*_GIT_OPTS
export) were silently dropped: read stopped at the first newline and
IFS only split on spaces, so the resulting array came out empty.

Split on spaces, tabs and newlines and consume the whole value with an
empty delimiter, ignoring leading/trailing whitespace.

Add unit tests covering space-, tab- and newline-separated inputs.
@coderabbitai

coderabbitai Bot commented Jun 22, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 6c324e95-93d6-4b9b-9ffa-94ac4883ee57

📥 Commits

Reviewing files that changed from the base of the PR and between f2ea9d1 and 5428cf7.

📒 Files selected for processing (2)
  • bin/git-forgit
  • tests/parse-array.test.sh

📝 Walkthrough

Walkthrough

_forgit_parse_array in bin/git-forgit is updated to split its input string on all whitespace (spaces, tabs, newlines) by setting IFS=$' \t\n' and using read -d '' -r -a instead of the prior space-only IFS=" ". A new test file tests/parse-array.test.sh is added with seven unit test cases covering the updated splitting behavior.

Changes

_forgit_parse_array whitespace splitting

Layer / File(s) Summary
_forgit_parse_array whitespace tokenizer
bin/git-forgit
Replaces IFS=" " with IFS=$' \t\n' and changes read to read -d '' -r -a, enabling splitting on spaces, tabs, and newlines.
Unit tests for _forgit_parse_array
tests/parse-array.test.sh
New test script sources bin/git-forgit, defines assert_parsed_array, and runs cases for space splitting, single values, empty input, newline-surrounded input, indented multi-line input, tab splitting, and whitespace-only input.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐇 A hop through the whitespace, tabs and newlines too,
No longer just spaces split values in two.
The array now reads with a \t\n delight,
And tests hop along to confirm it's just right.
The rabbit approves — every token in sight! 🌿

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 22.22% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main bug fix: supporting arbitrary whitespace in the _forgit_parse_array function.
Description check ✅ Passed The description includes a clear problem statement with a concrete example, explains the fix, confirms unit tests were added, and properly completes the repository's template checklist.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

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