1// Copyright Joyent, Inc. and other Node contributors. 2// 3// Permission is hereby granted, free of charge, to any person obtaining a 4// copy of this software and associated documentation files (the 5// "Software"), to deal in the Software without restriction, including 6// without limitation the rights to use, copy, modify, merge, publish, 7// distribute, sublicense, and/or sell copies of the Software, and to permit 8// persons to whom the Software is furnished to do so, subject to the 9// following conditions: 10// 11// The above copyright notice and this permission notice shall be included 12// in all copies or substantial portions of the Software. 13// 14// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 15// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN 17// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 18// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 19// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE 20// USE OR OTHER DEALINGS IN THE SOFTWARE. 21 22'use strict'; 23const common = require('../common'); 24const fixtures = require('../common/fixtures'); 25const assert = require('assert'); 26const path = require('path'); 27 28if (common.isWindows) { 29 const file = fixtures.path('a.js'); 30 const resolvedFile = path.resolve(file); 31 32 assert.strictEqual(path.toNamespacedPath(file), 33 `\\\\?\\${resolvedFile}`); 34 assert.strictEqual(path.toNamespacedPath(`\\\\?\\${file}`), 35 `\\\\?\\${resolvedFile}`); 36 assert.strictEqual(path.toNamespacedPath( 37 '\\\\someserver\\someshare\\somefile'), 38 '\\\\?\\UNC\\someserver\\someshare\\somefile'); 39 assert.strictEqual(path.toNamespacedPath( 40 '\\\\?\\UNC\\someserver\\someshare\\somefile'), 41 '\\\\?\\UNC\\someserver\\someshare\\somefile'); 42 assert.strictEqual(path.toNamespacedPath('\\\\.\\pipe\\somepipe'), 43 '\\\\.\\pipe\\somepipe'); 44} 45 46assert.strictEqual(path.toNamespacedPath(''), ''); 47assert.strictEqual(path.toNamespacedPath(null), null); 48assert.strictEqual(path.toNamespacedPath(100), 100); 49assert.strictEqual(path.toNamespacedPath(path), path); 50assert.strictEqual(path.toNamespacedPath(false), false); 51assert.strictEqual(path.toNamespacedPath(true), true); 52 53const emptyObj = {}; 54assert.strictEqual(path.posix.toNamespacedPath('/foo/bar'), '/foo/bar'); 55assert.strictEqual(path.posix.toNamespacedPath('foo/bar'), 'foo/bar'); 56assert.strictEqual(path.posix.toNamespacedPath(null), null); 57assert.strictEqual(path.posix.toNamespacedPath(true), true); 58assert.strictEqual(path.posix.toNamespacedPath(1), 1); 59assert.strictEqual(path.posix.toNamespacedPath(), undefined); 60assert.strictEqual(path.posix.toNamespacedPath(emptyObj), emptyObj); 61if (common.isWindows) { 62 // These tests cause resolve() to insert the cwd, so we cannot test them from 63 // non-Windows platforms (easily) 64 assert.strictEqual(path.toNamespacedPath(''), ''); 65 assert.strictEqual(path.win32.toNamespacedPath('foo\\bar').toLowerCase(), 66 `\\\\?\\${process.cwd().toLowerCase()}\\foo\\bar`); 67 assert.strictEqual(path.win32.toNamespacedPath('foo/bar').toLowerCase(), 68 `\\\\?\\${process.cwd().toLowerCase()}\\foo\\bar`); 69 const currentDeviceLetter = path.parse(process.cwd()).root.substring(0, 2); 70 assert.strictEqual( 71 path.win32.toNamespacedPath(currentDeviceLetter).toLowerCase(), 72 `\\\\?\\${process.cwd().toLowerCase()}`); 73 assert.strictEqual(path.win32.toNamespacedPath('C').toLowerCase(), 74 `\\\\?\\${process.cwd().toLowerCase()}\\c`); 75} 76assert.strictEqual(path.win32.toNamespacedPath('C:\\foo'), '\\\\?\\C:\\foo'); 77assert.strictEqual(path.win32.toNamespacedPath('C:/foo'), '\\\\?\\C:\\foo'); 78assert.strictEqual(path.win32.toNamespacedPath('\\\\foo\\bar'), 79 '\\\\?\\UNC\\foo\\bar\\'); 80assert.strictEqual(path.win32.toNamespacedPath('//foo//bar'), 81 '\\\\?\\UNC\\foo\\bar\\'); 82assert.strictEqual(path.win32.toNamespacedPath('\\\\?\\foo'), '\\\\?\\foo'); 83assert.strictEqual(path.win32.toNamespacedPath(null), null); 84assert.strictEqual(path.win32.toNamespacedPath(true), true); 85assert.strictEqual(path.win32.toNamespacedPath(1), 1); 86assert.strictEqual(path.win32.toNamespacedPath(), undefined); 87assert.strictEqual(path.win32.toNamespacedPath(emptyObj), emptyObj); 88