Skip to content

Commit 1aa8cbb

Browse files
committed
PR feedback
1 parent c41e7ec commit 1aa8cbb

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

templates/scripts/yamltotable.js.nontpl

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,17 @@ const headLines = [
1414

1515
function splitName(name) {
1616
const mp = name.split('/');
17+
if (mp.length !== 3) {
18+
throw new Error(`Invalid name: ${name}`);
19+
}
1720
// Check for characters outside of a-zA-Z0-9-_.
18-
const allowedChars = /[^a-zA-Z0-9-_.]/g;
21+
const allowedChars = /^[a-zA-Z0-9-_.]+$/;
1922
for (let i = 1; i <= 2; i++) {
2023
if (!allowedChars.test(mp[i])) {
2124
throw new Error(`Invalid character in ${name}: ${mp[i]}`);
2225
}
2326
}
24-
return [mp[0], mp[1]];
27+
return [mp[1], mp[2]];
2528
}
2629

2730
let modules = { [data.name]: data };
@@ -99,7 +102,11 @@ let firstLine = lines.indexOf("## Manifest Arguments");
99102
let lastLine = -1;
100103
if (firstLine !== -1) {
101104
let inTable = false;
105+
let otherSection = -1;
102106
for (let i = firstLine + 1; i < lines.length; i++) {
107+
if (otherSection === -1 && lines[i].startsWith("#")) {
108+
otherSection = i;
109+
}
103110
const isTable = lines[i].startsWith("|");
104111
if (inTable) {
105112
if (!isTable) {
@@ -111,7 +118,13 @@ if (firstLine !== -1) {
111118
}
112119
}
113120
if (lastLine === -1) {
114-
lastLine = Math.min(lines.length - 1, firstLine + headLines.length - 1);
121+
// Use last section if exists
122+
if (otherSection !== -1) {
123+
lastLine = otherSection - 2;
124+
} else {
125+
// Use end of file
126+
lastLine = lines.length - 1;
127+
}
115128
}
116129
}
117130

0 commit comments

Comments
 (0)