fix(v2): fix encoding of markdown image/file inline file-loaders (#4736)

* try to reproduce windows edge case due to file encoding

* mdx loader => required file paths should be escaped

* revert bad change

* try to fix posix path issues

* try to fix posix path issues

* attempt to fix the file-loader edge cases with non-ascii chars

* Add more example image edge-cases
This commit is contained in:
Sébastien Lorber 2021-05-06 16:48:20 +02:00 committed by GitHub
parent 39105f03d4
commit a79c70c954
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
12 changed files with 148 additions and 40 deletions

View file

@ -21,9 +21,14 @@ import {
// @ts-expect-error: no typedefs :s
import resolvePathnameUnsafe from 'resolve-pathname';
import {posixPath as posixPathImport} from './posixPath';
export const posixPath = posixPathImport;
export * from './codeTranslationsUtils';
export * from './markdownParser';
export * from './markdownLinks';
export * from './escapePath';
const fileHash = new Map();
export async function generate(
@ -129,20 +134,6 @@ export function genComponentName(pagePath: string): string {
return upperFirst(camelCase(pageHash));
}
/**
* Convert Windows backslash paths to posix style paths.
* E.g: endi\\lie -> endi/lie
*/
export function posixPath(str: string): string {
const isExtendedLengthPath = /^\\\\\?\\/.test(str);
const hasNonAscii = /[^\u0000-\u0080]+/.test(str); // eslint-disable-line
if (isExtendedLengthPath || hasNonAscii) {
return str;
}
return str.replace(/\\/g, '/');
}
// When you want to display a path in a message/warning/error,
// it's more convenient to:
// - make it relative to cwd()