mirror of
https://github.com/facebook/docusaurus.git
synced 2025-12-29 05:12:52 +00:00
* 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
28 lines
878 B
TypeScript
28 lines
878 B
TypeScript
/**
|
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
*
|
|
* This source code is licensed under the MIT license found in the
|
|
* LICENSE file in the root directory of this source tree.
|
|
*/
|
|
|
|
/**
|
|
* Convert Windows backslash paths to posix style paths.
|
|
* E.g: endi\\lie -> endi/lie
|
|
*
|
|
* Looks like this code was originally copied from https://github.com/sindresorhus/slash/blob/main/index.js
|
|
*
|
|
*/
|
|
export function posixPath(str: string): string {
|
|
const isExtendedLengthPath = /^\\\\\?\\/.test(str);
|
|
|
|
// TODO not sure why we need this
|
|
// See https://github.com/sindresorhus/slash/pull/16#issuecomment-833528479
|
|
// See https://github.com/facebook/docusaurus/issues/4730#issuecomment-833530370
|
|
const hasNonAscii = /[^\u0000-\u0080]+/.test(str); // eslint-disable-line
|
|
|
|
if (isExtendedLengthPath || hasNonAscii) {
|
|
return str;
|
|
}
|
|
return str.replace(/\\/g, '/');
|
|
}
|