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

os: handle empty path segments in join_path #19877

Merged
merged 4 commits into from
Nov 15, 2023

Conversation

ttytm
Copy link
Member

@ttytm ttytm commented Nov 14, 2023

Not handling empty path segments might result in an unexpected path. E.g. when there is a base variable that might be empty, a path would become a root path unintentionally.

Currently, it is:

base_var := ''
os.join_path(base_var, 'abc', '', '') == '/abc//'

With the changes it becomes 'abc'. This would be the same way go is joining paths. Where:

Join("", "abc", "", "") == "abc"

🤖 Generated by Copilot at a00c73b

This pull request improves the os.join_path function and its tests. It fixes a bug that caused incorrect paths when joining empty strings or strings with separators, and adds more test cases for different operating systems and scenarios.

🤖 Generated by Copilot at a00c73b

  • Fix a bug in os.join_path that would produce incorrect paths with empty strings or leading separators (link)
  • Add more test cases for os.join_path in os_test.v, covering empty and separator scenarios and using conditional compilation for different OSes (link)

vlib/os/os_test.c.v Outdated Show resolved Hide resolved
vlib/os/os.v Outdated Show resolved Hide resolved
@spytheman spytheman merged commit 4e43944 into vlang:master Nov 15, 2023
47 of 48 checks passed
@ttytm ttytm deleted the os/empty-path-segs branch December 15, 2023 22:09
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