Skip to content

Commit 094a6ed

Browse files
committed
Merge branch 'fix/windows-path' into develop
2 parents a9f3bf1 + 01dc8da commit 094a6ed

File tree

4 files changed

+13
-7
lines changed

4 files changed

+13
-7
lines changed

testsuite/tests/util/Context-node.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ describe('context object', () => {
1919

2020
test('context', () => {
2121
if (OS === 'Windows') {
22-
expect(context.path('C:\\test.js')).toBe('C:/test.js');
22+
expect(context.path('C:\\test.js')).toBe('file://C:/test.js');
2323
} else {
2424
expect(context.path('C:\\test.js')).toBe('C:\\test.js');
2525
}

testsuite/tests/util/Context-windows.test.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@ describe('context object', () => {
77

88
test('context', async () => {
99
let {context, hasWindow} = await import("#js/util/context.js");
10-
expect(context.path('C:\\test.js')).toBe('C:/test.js');
11-
expect(context.path('/C:/test.js')).toBe('C:/test.js');
12-
expect(context.path('/test.js')).toBe('/test.js');
10+
expect(context.path('C:\\test.js')).toBe('file://C:/test.js');
11+
expect(context.path('/C:/test.js')).toBe('file://C:/test.js');
12+
expect(context.path('/test.js')).toBe('file:///test.js');
13+
expect(context.path('./test.js')).toBe('./test.js');
1314
delete context.path;
1415
expect(context).toEqual({window: window, document: window.document, os: 'Windows'});
1516
expect(hasWindow).toBe(true);

ts/util/asyncLoad/system.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,12 @@ import { context } from '../context.js';
2727
declare const System: { import: (name: string, url?: string) => any };
2828
declare const __dirname: string;
2929

30-
let root = 'file://' + context.path(__dirname).replace(/\/[^/]*\/[^/]*$/, '/');
30+
let root =
31+
'file://' +
32+
context
33+
.path(__dirname)
34+
.replace(/\/[^/]*\/[^/]*$/, '/')
35+
.replace(/^file:\/\//, '');
3136

3237
if (!mathjax.asyncLoad && typeof System !== 'undefined' && System.import) {
3338
mathjax.asyncLoad = (name: string) => {

ts/util/context.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,6 @@ export const context = {
7575
if (context.os === 'Windows') {
7676
context.path = (file: string) =>
7777
file.match(/^[/\\]?[a-zA-Z]:[/\\]/)
78-
? file.replace(/\\/g, '/').replace(/^\//, '')
79-
: file;
78+
? 'file://' + file.replace(/\\/g, '/').replace(/^\//, '')
79+
: file.replace(/^\//, 'file:///');
8080
}

0 commit comments

Comments
 (0)