-
Notifications
You must be signed in to change notification settings - Fork 1
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
Conversation
### 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.
There was a problem hiding this 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 😅
linkup-cli/src/env_files.rs
Outdated
let expected_content = format!("{}\n{}", "EXISTING_1=VALUE_1", "EXISTING_2=VALUE_2",); | ||
assert_eq!(expected_content, file_content); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
linkup/linkup-cli/src/env_files.rs
Lines 84 to 86 in e60a633
if file_content.ends_with('\n') { | |
file_content.pop(); | |
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🤦
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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? 🤔
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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?
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.