• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

hildjj / node-inspect-extracted / 9053558361

12 May 2024 06:59PM UTC coverage: 97.922%. Remained the same
9053558361

push

github

hildjj
3.0.2

1812 of 1862 branches covered (97.31%)

Branch coverage included in aggregate %.

3749 of 3817 relevant lines covered (98.22%)

2306.02 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

94.12
/src/path.js
1
// Copyright Joyent, Inc. and other Node contributors.
12✔
2
//
12✔
3
// Permission is hereby granted, free of charge, to any person obtaining a
12✔
4
// copy of this software and associated documentation files (the
12✔
5
// "Software"), to deal in the Software without restriction, including
12✔
6
// without limitation the rights to use, copy, modify, merge, publish,
12✔
7
// distribute, sublicense, and/or sell copies of the Software, and to permit
12✔
8
// persons to whom the Software is furnished to do so, subject to the
12✔
9
// following conditions:
12✔
10
//
12✔
11
// The above copyright notice and this permission notice shall be included
12✔
12
// in all copies or substantial portions of the Software.
12✔
13
//
12✔
14
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
12✔
15
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
12✔
16
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
12✔
17
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
12✔
18
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
12✔
19
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
12✔
20
// USE OR OTHER DEALINGS IN THE SOFTWARE.
12✔
21

12✔
22
'use strict';
12✔
23

12✔
24
const {
12✔
25
  StringPrototypeCharCodeAt,
12✔
26
  StringPrototypeLastIndexOf,
12✔
27
  StringPrototypeSlice,
12✔
28
} = require('./primordials');
12✔
29

12✔
30
const {
12✔
31
  CHAR_DOT,
12✔
32
  CHAR_FORWARD_SLASH,
12✔
33
} = require('./internal/constants');
12✔
34
const {
12✔
35
  validateString,
12✔
36
} = require('./internal/validators');
12✔
37

12✔
38
function posixCwd() {
32✔
39
  return '/'; // Fake for the web case
32✔
40
}
32✔
41

12✔
42
function isPosixPathSeparator(code) {
1,800✔
43
  return code === CHAR_FORWARD_SLASH;
1,800✔
44
}
1,800✔
45

12✔
46
// Resolves . and .. elements in a path with directory names
12✔
47
function normalizeString(path, allowAboveRoot, separator, isPathSeparator) {
144✔
48
  let res = '';
144✔
49
  let lastSegmentLength = 0;
144✔
50
  let lastSlash = -1;
144✔
51
  let dots = 0;
144✔
52
  let code = 0;
144✔
53
  for (let i = 0; i <= path.length; ++i) {
144✔
54
    if (i < path.length)
1,800✔
55
      code = StringPrototypeCharCodeAt(path, i);
1,800✔
56
    else if (isPathSeparator(code))
144✔
57
      break;
144✔
58
    else
×
59
      code = CHAR_FORWARD_SLASH;
×
60

1,656✔
61
    if (isPathSeparator(code)) {
1,800✔
62
      if (lastSlash === i - 1 || dots === 1) {
432✔
63
        // NOOP
208✔
64
      } else if (dots === 2) {
432✔
65
        if (res.length < 2 || lastSegmentLength !== 2 ||
28!
66
            StringPrototypeCharCodeAt(res, res.length - 1) !== CHAR_DOT ||
28!
67
            StringPrototypeCharCodeAt(res, res.length - 2) !== CHAR_DOT) {
28✔
68
          if (res.length > 2) {
28✔
69
            const lastSlashIndex = StringPrototypeLastIndexOf(res, separator);
16✔
70
            if (lastSlashIndex === -1) {
16✔
71
              res = '';
4✔
72
              lastSegmentLength = 0;
4✔
73
            } else {
16✔
74
              res = StringPrototypeSlice(res, 0, lastSlashIndex);
12✔
75
              lastSegmentLength =
12✔
76
                res.length - 1 - StringPrototypeLastIndexOf(res, separator);
12✔
77
            }
12✔
78
            lastSlash = i;
16✔
79
            dots = 0;
16✔
80
            continue;
16✔
81
          } else if (res.length !== 0) {
28✔
82
            res = '';
4✔
83
            lastSegmentLength = 0;
4✔
84
            lastSlash = i;
4✔
85
            dots = 0;
4✔
86
            continue;
4✔
87
          }
4✔
88
        }
28✔
89
        if (allowAboveRoot) {
28!
90
          res += res.length > 0 ? `${separator}..` : '..';
×
91
          lastSegmentLength = 2;
×
92
        }
×
93
      } else {
224✔
94
        if (res.length > 0)
196✔
95
          res += `${separator}${StringPrototypeSlice(path, lastSlash + 1, i)}`;
196✔
96
        else
136✔
97
          res = StringPrototypeSlice(path, lastSlash + 1, i);
136✔
98
        lastSegmentLength = i - lastSlash - 1;
196✔
99
      }
196✔
100
      lastSlash = i;
412✔
101
      dots = 0;
412✔
102
    } else if (code === CHAR_DOT && dots !== -1) {
1,800✔
103
      ++dots;
56✔
104
    } else {
1,224✔
105
      dots = -1;
1,168✔
106
    }
1,168✔
107
  }
1,800✔
108
  return res;
144✔
109
}
144✔
110

12✔
111
function resolve(...args) {
144✔
112
  let resolvedPath = '';
144✔
113
  let resolvedAbsolute = false;
144✔
114

144✔
115
  for (let i = args.length - 1; i >= -1 && !resolvedAbsolute; i--) {
144✔
116
    const path = i >= 0 ? args[i] : posixCwd();
196✔
117

196✔
118
    validateString(path, 'path');
196✔
119

196✔
120
    // Skip empty entries
196✔
121
    if (path.length === 0) {
196✔
122
      continue;
4✔
123
    }
4✔
124

192✔
125
    resolvedPath = `${path}/${resolvedPath}`;
192✔
126
    resolvedAbsolute =
192✔
127
      StringPrototypeCharCodeAt(path, 0) === CHAR_FORWARD_SLASH;
192✔
128
  }
192✔
129

144✔
130
  // At this point the path should be resolved to a full absolute path, but
144✔
131
  // handle relative paths to be safe (might happen when process.cwd() fails)
144✔
132

144✔
133
  // Normalize the path
144✔
134
  resolvedPath = normalizeString(resolvedPath, !resolvedAbsolute, '/',
144✔
135
                                 isPosixPathSeparator);
144✔
136

144✔
137
  if (resolvedAbsolute) {
144✔
138
    return `/${resolvedPath}`;
144✔
139
  }
144✔
140
  return resolvedPath.length > 0 ? resolvedPath : '.';
144!
141
}
144✔
142

12✔
143
module.exports = {
12✔
144
  resolve,
12✔
145
};
12✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc