fix(utils): properly escape Windows paths (#6190)

* fix(utils): properly escape Windows paths

* Use in more places

* Escape path in test

* Fix snapshot

* Better comment

* Fix tests
This commit is contained in:
Joshua Chen 2021-12-25 15:24:21 +08:00 committed by GitHub
parent 6716548b87
commit f02fefb5b7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 38 additions and 37 deletions

View file

@ -11,7 +11,6 @@ import mdx from 'remark-mdx';
import vfile from 'to-vfile';
import plugin from '../index';
import headings from '../../headings/index';
import {posixPath} from '@docusaurus/utils';
const processFixture = async (name, options) => {
const filePath = path.join(__dirname, `__fixtures__/${name}.md`);
@ -24,7 +23,8 @@ const processFixture = async (name, options) => {
return result
.toString()
.replace(new RegExp(posixPath(process.cwd()), 'g'), '[CWD]');
.replace(/\\\\/g, '/')
.replace(new RegExp(process.cwd().replace(/\\/g, '/'), 'g'), '[CWD]');
};
const staticDirs = [

View file

@ -11,7 +11,6 @@ import mdx from 'remark-mdx';
import vfile from 'to-vfile';
import plugin from '..';
import transformImage from '../../transformImage';
import {posixPath} from '@docusaurus/utils';
const processFixture = async (name: string, options?) => {
const filePath = path.join(__dirname, `__fixtures__/${name}.md`);
@ -33,7 +32,8 @@ const processFixture = async (name: string, options?) => {
return result
.toString()
.replace(new RegExp(posixPath(process.cwd()), 'g'), '[CWD]');
.replace(/\\\\/g, '/')
.replace(new RegExp(process.cwd().replace(/\\/g, '/'), 'g'), '[CWD]');
};
describe('transformAsset plugin', () => {