Skip to content

[Windows] App Crashes when path contains non-latin characters #1093

@jihoobyeon

Description

@jihoobyeon

I made a simple React Native for Windows app for practice, which write a sentence of plain text and read that file to show the content at window.
this is my App.ts:

import { Component, createElement } from 'react';
import { Text } from 'react-native';
import { readFile, writeFile } from 'react-native-fs';

class FileIO {
	protected path = 'C:\\Users\\변지후\\Desktop\\';

	constructor(file_name: string) {
		this.path += file_name;
	}

	public read() {
		return readFile(this.path)
			.then(content => {
				return content;
			})
			.catch(e => {
				console.log(e.code + ':\t' + e.message);
			});
	}

	public write(file_content: string) {
		writeFile(this.path, file_content)
			.catch(e => {
				console.log(e.code + ':\t' + e.message);
			});
	}
}

export default class App extends Component<undefined, { str: string }> {
	constructor(props: any) {
		super(props);
		this.state = { str: '' };
	}

	protected io = new FileIO('test.txt');

	async componentDidMount() {
		this.io.write('The quick brown fox jumps over the lazy dog.\n');
		const file_str = await this.io.read();
		this.setState({ str: file_str });
	}

	render() {
		return createElement(Text, undefined, this.state.str);
	}
}

but when I run this app, the UWP window appears, but disappears before contents being rendered.
there are NO error message at Debugger UI.

note: this is my result of npx react-native info:

System:
    OS: Windows 10 10.0.19043
    CPU: (4) x64 AMD Ryzen 3 2200U with Radeon Vega Mobile Gfx
    Memory: 2.50 GB / 7.63 GB
  Binaries:
    Node: 16.13.0 - C:\Program Files\nodejs\node.EXE
    Yarn: 1.22.18 - ~\AppData\Roaming\npm\yarn.CMD
    npm: 8.1.0 - C:\Program Files\nodejs\npm.CMD
    Watchman: Not Found
  SDKs:
    Android SDK: Not Found
    Windows SDK:
      AllowDevelopmentWithoutDevLicense: Enabled
      AllowAllTrustedApps: Enabled
      Versions: 10.0.19041.0, 10.0.22000.0
  IDEs:
    Android Studio: Not Found
    Visual Studio: 16.11.32228.343 (Visual Studio Community 2019)
  Languages:
    Java: Not Found
  npmPackages:
    @react-native-community/cli: Not Found
    react: 17.0.2 => 17.0.2
    react-native: 0.66.4 => 0.66.4
    react-native-windows: 0.66.16 => 0.66.16
  npmGlobalPackages:
    *react-native*: Not Found

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions