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 edge case in path.relative. #3952

Merged
merged 1 commit into from
Aug 3, 2023
Merged

Conversation

Hanaasagi
Copy link
Collaborator

Close: #3924

What does this PR do?

  • path.relative("/webpack-hot-middleware", "/webpack/buildin/module.js") should return ../webpack/buildin/module.js

Some explanations.

Assuming the input is as follows:

  • input[0] => /webpack-hot-middleware
  • input[1] => /webpack/buildin/module.js

2 => {
while (index < min_length) : (index += 1) {
if (input[0][index] != input[1][index]) {
break;
}
if (@call(.always_inline, isPathSeparator, .{input[0][index]})) {
last_common_separator = index;
}
}
},

The longest common substring is /webpack, So the index is 8 (point to - or /).

But here

for (input) |str| {
if (str.len > index) {
if (@call(.always_inline, isPathSeparator, .{str[index]})) {
return str[0 .. index + 1];
}
}
}

we will get /webpack/ here, a wrong directory.

  • Documentation or TypeScript types (it's okay to leave the rest blank in this case)
  • Code changes

How did you verify your code works?

I wrote automated tests

@Hanaasagi Hanaasagi force-pushed the fix-relative branch 2 times, most recently from eeafe8e to e412222 Compare August 3, 2023 14:51
@Hanaasagi Hanaasagi changed the title Fix edge case inf path.relative. Fix edge case in path.relative. Aug 3, 2023
@Jarred-Sumner
Copy link
Collaborator

Thank you! Let's see the tests run if anything interesting happens. Changes to path resolution often have a lot of unexpected side effects, though nowadays we have much better test coverage so I expect any issues to come up in tests

@Jarred-Sumner Jarred-Sumner merged commit a4d996c into oven-sh:main Aug 3, 2023
trnxdev pushed a commit to trnxdev/bun that referenced this pull request Aug 9, 2023
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.

path.relative edge case
2 participants