-
Notifications
You must be signed in to change notification settings - Fork 30.1k
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
UTF Characters for relative path #27534
Comments
The problem here is that There's an easy fix for this case: console.log(path.win32.relative('c:\\a\\İ', 'c:\\a\\İ\\test.txt'));
// est.txt diff --git a/lib/path.js b/lib/path.js
index 2301a6ebb8..e76513f0f3 100644
--- a/lib/path.js
+++ b/lib/path.js
@@ -499,7 +499,7 @@ const win32 = {
if (to.charCodeAt(toStart + i) === CHAR_BACKWARD_SLASH) {
// We get here if `from` is the exact base path for `to`.
// For example: from='C:\\foo\\bar'; to='C:\\foo\\bar\\baz'
- return toOrig.slice(toStart + i + 1);
+ return toOrig.slice(toStart + i + 1 - from.length + fromOrig.length);
}
if (i === 2) {
// We get here if `from` is the device root. console.log(path.win32.relative('c:\\a\\İ', 'c:\\a\\İ\\test.txt'));
// test.txt However this case is trickier: console.log(path.win32.relative('c:\\İ\\a\\İ', 'c:\\İ\\b\\İ\\test.txt'));
// ..\..b\İ\test.txt |
This should be easy to fix: instead of using the lower cased variation it's possible to use the upper case one. These two ways do not work identical and the upper case variation does not show the negative sides as the lower case. I am compiling right now to see if that works as expected. |
|
@BridgeAR what about: |
Sorry ^. That's not the example I meant. Isn't there the same risk with |
@BridgeAR Make sure this case works as well: |
@targos @mathiasbynens PTAL. |
I'm afraid the behavior of |
@targos yes, that's correct. As far as I know a device name may also contain unicode characters and if that's the case also I have to think about this a bit closer when I find to do so. We probably also have issues even without changing the casing since we expect characters to always have a length of 1. This is mostly not an issue, since we almost always just check for slashes and take everything in-between but we expect the device root to always be of length 2. |
This commit changes the way two paths are compared in path.relative: Instead of comparing each char code in path strings one by one, which causes problems when the number of char codes in lowercased path string does not match the original one (e.g. path contains certain Unicode characters like 'İ'), it now splits the path string by backslash and compares the parts instead. Fixes: nodejs#27534
This is still an issue that can lead to bugs in August 2021. Any news? |
This commit changes the way two paths are compared in path.relative: Instead of comparing each char code in path strings one by one, which causes problems when the number of char codes in lowercased path string does not match the original one (e.g. path contains certain Unicode characters like 'İ'), it now splits the path string by backslash and compares the parts instead. Fixes: nodejs#27534
This commit changes the way two paths are compared in path.relative: Instead of comparing each char code in path strings one by one, which causes problems when the number of char codes in lowercased path string does not match the original one (e.g. path contains certain Unicode characters like 'İ'), it now splits the path string by backslash and compares the parts instead. Fixes: nodejs#27534
Version: 10.15.3
Platform: Windows 64bit
Subsystem: "path" module
Expected result:
test.txt
Actual result:
est.txt
The text was updated successfully, but these errors were encountered: