Skip to content

path: fix relative on Windows

This PR fixes the bug in win32.relative(). Since converting to lowercase changes the length of the original path, which contains UTF characters such as "İ", the algorithm only works in this condition.

Benchmark results are:

                                                                                                                        confidence improvement accuracy (*)   (**)   (***)
path\\relative-win32.js n=100000 paths='C:\\\\|D:\\\\'                                                                                  3.21 %       ±6.44% ±8.57% ±11.17%
path\\relative-win32.js n=100000 paths='C:\\\\foo\\\\bar\\\\baz\\\\quux|C:\\\\'                                                         0.14 %       ±5.44% ±7.26%  ±9.48%
path\\relative-win32.js n=100000 paths='C:\\\\foo\\\\bar\\\\baz|C:\\\\foo\\\\bar\\\\baz'                                               -1.87 %       ±5.55% ±7.38%  ±9.61%
path\\relative-win32.js n=100000 paths='C:\\\\foo\\\\BAR\\\\BAZ|C:\\\\foo\\\\bar\\\\baz'                                                0.84 %       ±4.61% ±6.14%  ±7.99%
path\\relative-win32.js n=100000 paths='c:\\\\İ\\\\a\\\\İ|c:\\\\İ\\\\b\\\\İ\\\\test.txt|..\\\\..\\\\b\\\\İ\\\\test.txt'        ***    -38.79 %       ±5.20% ±6.95%  ±9.12%
path\\relative-win32.js n=100000 paths='C:\\\\orandea\\\\test\\\\aaa|C:\\\\orandea\\\\impl\\\\bbb'                                      1.65 %       ±6.11% ±8.13% ±10.58%

Suggestions to improve performance are welcome.

Fixes: https://github.com/nodejs/node/issues/27534

Merge request reports

Loading