module: fix bad `require.resolve` with option paths for `.` and `..` · nodejs/node@5e2dab7
@@ -693,18 +693,8 @@ Module._findPath = function(request, paths, isMain) {
693693)
694694));
695695696-const isRelative = StringPrototypeCharCodeAt(request, 0) === CHAR_DOT &&
697-(
698-request.length === 1 ||
699-StringPrototypeCharCodeAt(request, 1) === CHAR_FORWARD_SLASH ||
700-(isWindows && StringPrototypeCharCodeAt(request, 1) === CHAR_BACKWARD_SLASH) ||
701-(StringPrototypeCharCodeAt(request, 1) === CHAR_DOT && ((
702-request.length === 2 ||
703-StringPrototypeCharCodeAt(request, 2) === CHAR_FORWARD_SLASH) ||
704-(isWindows && StringPrototypeCharCodeAt(request, 2) === CHAR_BACKWARD_SLASH)))
705-);
706696let insidePath = true;
707-if (isRelative) {
697+if (isRelative(request)) {
708698const normalizedRequest = path.normalize(request);
709699if (StringPrototypeStartsWith(normalizedRequest, '..')) {
710700insidePath = false;
@@ -1147,12 +1137,7 @@ Module._resolveFilename = function(request, parent, isMain, options) {
1147113711481138if (typeof options === 'object' && options !== null) {
11491139if (ArrayIsArray(options.paths)) {
1150-const isRelative = StringPrototypeStartsWith(request, './') ||
1151-StringPrototypeStartsWith(request, '../') ||
1152-((isWindows && StringPrototypeStartsWith(request, '.\\')) ||
1153-StringPrototypeStartsWith(request, '..\\'));
1154-1155-if (isRelative) {
1140+if (isRelative(request)) {
11561141paths = options.paths;
11571142} else {
11581143const fakeParent = new Module('', null);
@@ -1715,6 +1700,21 @@ function createRequire(filename) {
17151700return createRequireFromPath(filepath);
17161701}
171717021703+/**
1704+ * Checks if a path is relative
1705+ * @param {string} path the target path
1706+ * @returns {boolean} true if the path is relative, false otherwise
1707+ */
1708+function isRelative(path) {
1709+if (StringPrototypeCharCodeAt(path, 0) !== CHAR_DOT) { return false; }
1710+1711+return path.length === 1 || path === '..' ||
1712+StringPrototypeStartsWith(path, './') ||
1713+StringPrototypeStartsWith(path, '../') ||
1714+((isWindows && StringPrototypeStartsWith(path, '.\\')) ||
1715+StringPrototypeStartsWith(path, '..\\'));
1716+}
1717+17181718Module.createRequire = createRequire;
1719171917201720/**