fix(utils): remove non-ASCII limitation for path normalization (#8137)

This commit is contained in:
Johan Fagerberg 2022-10-07 13:35:12 +02:00 committed by GitHub
parent efbd0cbd40
commit 6c8af03f51
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 4 additions and 7 deletions

View file

@ -156,7 +156,7 @@ describe('posixPath', () => {
it('works', () => { it('works', () => {
const asserts: {[key: string]: string} = { const asserts: {[key: string]: string} = {
'c:/aaaa\\bbbb': 'c:/aaaa/bbbb', 'c:/aaaa\\bbbb': 'c:/aaaa/bbbb',
'c:\\aaaa\\bbbb\\★': 'c:\\aaaa\\bbbb\\★', 'c:\\aaaa\\bbbb\\★': 'c:/aaaa/bbbb/★',
'\\\\?\\c:\\aaaa\\bbbb': '\\\\?\\c:\\aaaa\\bbbb', '\\\\?\\c:\\aaaa\\bbbb': '\\\\?\\c:\\aaaa\\bbbb',
'c:\\aaaa\\bbbb': 'c:/aaaa/bbbb', 'c:\\aaaa\\bbbb': 'c:/aaaa/bbbb',
'foo\\bar': 'foo/bar', 'foo\\bar': 'foo/bar',

View file

@ -58,12 +58,7 @@ export function shortName(str: string): string {
export function posixPath(str: string): string { export function posixPath(str: string): string {
const isExtendedLengthPath = str.startsWith('\\\\?\\'); const isExtendedLengthPath = str.startsWith('\\\\?\\');
// Forward slashes are only valid Windows paths when they don't contain non- if (isExtendedLengthPath) {
// ascii characters.
// eslint-disable-next-line no-control-regex
const hasNonAscii = /[^\u0000-\u0080]+/.test(str);
if (isExtendedLengthPath || hasNonAscii) {
return str; return str;
} }
return str.replace(/\\/g, '/'); return str.replace(/\\/g, '/');

View file

@ -0,0 +1 @@
Dogfood test for https://github.com/facebook/docusaurus/pull/8137

View file

@ -0,0 +1 @@
Dogfood test for https://github.com/facebook/docusaurus/pull/8137