Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: conditionally strip chars from first line #272

Merged
merged 2 commits into from
Dec 18, 2024
Merged

Conversation

a-frantz
Copy link
Member

@a-frantz a-frantz commented Dec 17, 2024

Describe the problem or feature in addition to a link to the issues.

Applies the #271 fix to multiline strings as well as command sections.

Before submitting this PR, please make sure:

  • You have added a few sentences describing the PR here.
  • You have added yourself or the appropriate individual as the assignee.
  • You have added at least one relevant code reviewer to the PR.
  • Your code builds clean without any errors or warnings.
  • You have added tests (when appropriate).
  • You have updated the README or other documentation to account for these
    changes (when appropriate).
  • You have added an entry to the relevant CHANGELOG.md (see
    "keep a changelog" for more information).
  • Your commit messages follow the conventional commit style.

@a-frantz a-frantz self-assigned this Dec 17, 2024
@a-frantz a-frantz marked this pull request as ready for review December 17, 2024 17:30
@a-frantz a-frantz requested a review from peterhuene December 17, 2024 17:40
Copy link
Member Author

@a-frantz a-frantz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oops my comment didn't go through

assert_eq!(stripped.len(), 1);
match &stripped[0] {
StrippedStringPart::Text(text) => {
assert_eq!(text.as_str(), "hello world\n my name is Jeff.")
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@peterhuene is this correct, or should it be "hello world\nmy name is Jeff."?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From my reading of the spec, I think this is the expected output.

According to the spec the order of operations is:

  1. Remove all line continuations and subsequent white space.
  2. Remove all whitespace following the opening <<<, up to and including a newline (if any).
  3. Remove all whitespace preceeding the closing >>>, up to and including a newline (if any).
  4. Use all remaining non-blank lines to determine the common leading whitespace.
  5. Strip leading whitespace.

I think we're now faithfully following these steps; we remove line continuations first, then the <<< and >>> whitespace, then we calculate the minimum leading whitespace from every non-blank line, then we strip the leading whitespace.

In this case, as we remove the whitespace on the first line in step 2, we determine the minimum leading whitespace to be 0 because hello world is the first non-blank line; as a result, the leading whitespace remains.

@a-frantz a-frantz merged commit 8681548 into main Dec 18, 2024
16 checks passed
@a-frantz a-frantz deleted the fix/268-take2 branch December 18, 2024 19:27
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