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: off by one error env file without new line #62

Merged
merged 3 commits into from
Feb 26, 2024

Conversation

augustoccesar
Copy link
Collaborator

Description

When looking into the start index of the matching, it gets the index of the initial matching char. Which means that to get the last char, we should add the size of the separator - 1 to take into consideration that the index start on the first char.

### Description
When looking into the start index of the matching, it gets the index of the initial matching char. Which means that to get the last char, we should add the size of the separator - 1 to take into consideration that the index start on the first char.
Copy link
Contributor

@ostenbom ostenbom left a comment

Choose a reason for hiding this comment

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

Thanks ⭐ ⭐ Boy am I happy there are unit tests here 😅

Comment on lines 232 to 233
let expected_content = format!("{}\n{}", "EXISTING_1=VALUE_1", "EXISTING_2=VALUE_2",);
assert_eq!(expected_content, file_content);
Copy link
Contributor

Choose a reason for hiding this comment

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

I wonder if linkup should always add a newline at the end of the file if there isn't one?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We can do that as well! Right now we are explicitly removing a last new line if there is one 🤔

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

if file_content.ends_with('\n') {
file_content.pop();
}

Copy link
Contributor

Choose a reason for hiding this comment

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

🤦

Copy link
Contributor

Choose a reason for hiding this comment

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

I think this was to fix the case where this happened:

\n
\n
\n

and the file kept growing

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Maybe we can remove any repeating trailing \n to ensure there is only one left by the end of it? 🤔

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah that sounds like a solid solution

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

What do you think of 34ebcfb?

@ostenbom ostenbom merged commit 85ff2f7 into main Feb 26, 2024
4 checks passed
@ostenbom ostenbom deleted the fix/clean-env-files-without-new-line branch February 26, 2024 15:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants