url: provide pathToFileURL and fileURLToPath

PR-URL: https://github.com/nodejs/node/pull/22506
Reviewed-By: John-David Dalton <john.david.dalton@gmail.com>
Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Bradley Farias <bradley.meck@gmail.com>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Reviewed-By: Gus Caplan <me@gus.host>
This commit is contained in:
guybedford committed 2018-09-04 16:08:21 +02:00
1 parent 0d3da39f57
commit eef072fa08
13 files changed
+208 -112

No files matched your search

+24
View File
@@ -0,0 +1,24 @@
'use strict';
const { isWindows } = require('../common');
const assert = require('assert');
const url = require('url');
{
const fileURL = url.pathToFileURL('test/').href;
assert.ok(fileURL.startsWith('file:///'));
assert.ok(fileURL.endsWith('/'));
}
{
const fileURL = url.pathToFileURL('test\\').href;
assert.ok(fileURL.startsWith('file:///'));
if (isWindows)
assert.ok(fileURL.endsWith('/'));
else
assert.ok(fileURL.endsWith('%5C'));
}
{
const fileURL = url.pathToFileURL('test/%').href;
assert.ok(fileURL.includes('%25'));
}