-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprefixRepair.js
45 lines (35 loc) · 1.19 KB
/
prefixRepair.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
const core = require('@actions/core');
/**
* @param {string} path
* @return {string|null}
*/
let prefixRepair = function (path) {
if (typeof path !== 'string') {
core.setFailed('path is not type string!');
throw new Error('Error from prefixRepair.js - path is not type string!');
}
if (path.length === 0) {
core.setFailed('path.length is zero!');
throw new Error('Error from prefixRepair.js - path.length is zero!');
}
if (path.includes('..')) {
core.setFailed('path should not contain ".."!');
throw new Error('Error from prefixRepair.js - path should not contain ".."!');
}
if (path.startsWith('./')) {
// './example'
return path;
}
if (path.startsWith('/')) {
// '/example'
core.info('prefixRepair.js - it is not allowed to start path with "/" - script prefixed it with "."');
return ('.' + path);
}
if (path.startsWith('.')) {
// '.example'
core.info('prefixRepair.js - it is not allowed to start path with "." - script prefixed path with "./"');
return ('./' + path.slice(1, 99));
}
return ('./' + path);
};
module.exports = prefixRepair;