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

Windows (native build) codepage issues #1473

Open
Nik-mmzd opened this issue Apr 23, 2024 · 4 comments
Open

Windows (native build) codepage issues #1473

Nik-mmzd opened this issue Apr 23, 2024 · 4 comments

Comments

@Nik-mmzd
Copy link

Example code:

# main.kt
import okio.*
import okio.Path.Companion.toPath

fun main(args: Array<String>) {
    FileSystem.SYSTEM.createDirectory("тестовая строка".toPath())
}
# build.gradle.kts
plugins {
    kotlin("multiplatform") version "1.9.23"
}

repositories {
    mavenCentral()
}

kotlin {
    mingwX64 {
        binaries {
            executable()
        }
    }

    sourceSets {
        commonMain {
            dependencies {
                implementation("com.squareup.okio:okio:3.9.0")
            }
        }
    }
}

Provided code creates directory named тестовая строка (cp1251 represenation of utf-8 string) instead of тестовая строка.

This applies to other functions as well: FileSystem.SYSTEM.exists(), FileSystem.SYSTEM.write(), etc.

Tested on Windows 11 and Windows 10. "Unicode (beta)" in "Administrative Locale Settings" should be off.
When "Unicode beta" in "Administrative Locale Settings" is on, the issue is not reproducible.

@Nik-mmzd Nik-mmzd changed the title Windows codepage issues Windows (native build) codepage issues Apr 23, 2024
@swankjesse
Copy link
Collaborator

Thanks for reporting this.

I think there’s likely two possible fixes; one where we transcode the native path to UTF-8 first, and one where we don’t do that.

I’m curious what happens for Java, which uses UTF-16 strings for paths. It might just work because it does string encoding before it makes system calls.

@Nik-mmzd
Copy link
Author

Nik-mmzd commented Apr 23, 2024

Windows, same code, JVM target, JVM 17, all seems to be OK

@Nik-mmzd
Copy link
Author

I think I should note that cp1251 is locale-dependent codepage and may be changed by user in "Administrative Locale Settings". Current codepage can be retrieved using GetACP call.

@fzhinkin
Copy link

fzhinkin commented Sep 9, 2024

I’m curious what happens for Java, which uses UTF-16 strings for paths. It might just work because it does string encoding before it makes system calls.

Java uses API that accepts UTF-16 strings (LPCWSTR) as paths (CreateFileW, DeleteFileW, etc.): https://github.com/openjdk/jdk/blob/master/src/java.base/windows/native/libnio/fs/WindowsNativeDispatcher.c

@JakeWharton JakeWharton removed the bug label Oct 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants