|
22 | 22 | 'use strict';
|
23 | 23 |
|
24 | 24 | const {
|
| 25 | + ArrayPrototypeJoin, |
| 26 | + ArrayPrototypeSlice, |
25 | 27 | FunctionPrototypeBind,
|
26 | 28 | StringPrototypeCharCodeAt,
|
27 | 29 | StringPrototypeIndexOf,
|
28 | 30 | StringPrototypeLastIndexOf,
|
| 31 | + StringPrototypeRepeat, |
29 | 32 | StringPrototypeReplace,
|
30 | 33 | StringPrototypeSlice,
|
| 34 | + StringPrototypeSplit, |
31 | 35 | StringPrototypeToLowerCase,
|
32 | 36 | } = primordials;
|
33 | 37 |
|
@@ -540,6 +544,42 @@ const win32 = {
|
540 | 544 | if (from === to)
|
541 | 545 | return '';
|
542 | 546 |
|
| 547 | + if (fromOrig.length !== from.length || toOrig.length !== to.length) { |
| 548 | + const fromSplit = StringPrototypeSplit(fromOrig, '\\'); |
| 549 | + const toSplit = StringPrototypeSplit(toOrig, '\\'); |
| 550 | + if (fromSplit[fromSplit.length - 1] === '') { |
| 551 | + fromSplit.pop(); |
| 552 | + } |
| 553 | + if (toSplit[toSplit.length - 1] === '') { |
| 554 | + toSplit.pop(); |
| 555 | + } |
| 556 | + |
| 557 | + const fromLen = fromSplit.length; |
| 558 | + const toLen = toSplit.length; |
| 559 | + const length = fromLen < toLen ? fromLen : toLen; |
| 560 | + |
| 561 | + let i; |
| 562 | + for (i = 0; i < length; i++) { |
| 563 | + if (StringPrototypeToLowerCase(fromSplit[i]) !== StringPrototypeToLowerCase(toSplit[i])) { |
| 564 | + break; |
| 565 | + } |
| 566 | + } |
| 567 | + |
| 568 | + if (i === 0) { |
| 569 | + return toOrig; |
| 570 | + } else if (i === length) { |
| 571 | + if (toLen > length) { |
| 572 | + return ArrayPrototypeJoin(ArrayPrototypeSlice(toSplit, i), '\\'); |
| 573 | + } |
| 574 | + if (fromLen > length) { |
| 575 | + return StringPrototypeRepeat('..\\', fromLen - 1 - i) + '..'; |
| 576 | + } |
| 577 | + return ''; |
| 578 | + } |
| 579 | + |
| 580 | + return StringPrototypeRepeat('..\\', fromLen - i) + ArrayPrototypeJoin(ArrayPrototypeSlice(toSplit, i), '\\'); |
| 581 | + } |
| 582 | + |
543 | 583 | // Trim any leading backslashes
|
544 | 584 | let fromStart = 0;
|
545 | 585 | while (fromStart < from.length &&
|
|
0 commit comments