Skip to content

Commit aed4c9f

Browse files
committed
MRVA: Make markdown code snippets look nicer
Remove some extraneous newlines
1 parent 1a03c0e commit aed4c9f

5 files changed

Lines changed: 19 additions & 33 deletions

File tree

extensions/ql-vscode/src/remote-queries/remote-queries-markdown-generation.ts

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -113,11 +113,17 @@ function generateMarkdownForCodeSnippet(
113113
.map((line, index) =>
114114
highlightCodeLines(line, index + snippetStartLine, highlightedRegion)
115115
);
116-
lines.push(
117-
`<pre><code class="${language}">`,
118-
...codeLines,
119-
'</code></pre>',
120-
);
116+
117+
// Make sure there are no extra newlines before or after the <code> block:
118+
if (codeLines.length === 1) {
119+
lines.push(`<pre><code class="${language}">${codeLines[0]}</code></pre>`);
120+
} else {
121+
lines.push(
122+
`<pre><code class="${language}">${codeLines[0]}`,
123+
...codeLines.slice(1, -1),
124+
`${codeLines[codeLines.length - 1]}</code></pre>`,
125+
);
126+
}
121127
lines.push('');
122128
return lines;
123129
}

extensions/ql-vscode/test/pure-tests/remote-queries/markdown-generation/data/interpreted-results/path-problem/results-repo1.md

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,10 @@
22

33
[javascript/ql/src/Security/CWE-078/examples/shell-command-injection-from-environment.js](https://github.com/github/codeql/blob/48015e5a2e6202131f2d1062cc066dc33ed69a9b/javascript/ql/src/Security/CWE-078/examples/shell-command-injection-from-environment.js#L5-L5)
44

5-
<pre><code class="javascript">
6-
function cleanupTemp() {
5+
<pre><code class="javascript">function cleanupTemp() {
76
let cmd = "rm -rf " + path.join(__dirname, "temp");
87
cp.execSync(<strong>cmd</strong>); // BAD
98
}
10-
119
</code></pre>
1210

1311
*This shell command depends on an uncontrolled [absolute path](https://github.com/github/codeql/blob/48015e5a2e6202131f2d1062cc066dc33ed69a9b/javascript/ql/src/Security/CWE-078/examples/shell-command-injection-from-environment.js#L4-L4).*
@@ -16,13 +14,11 @@ function cleanupTemp() {
1614

1715
[javascript/ql/test/query-tests/Security/CWE-078/tst_shell-command-injection-from-environment.js](https://github.com/github/codeql/blob/48015e5a2e6202131f2d1062cc066dc33ed69a9b/javascript/ql/test/query-tests/Security/CWE-078/tst_shell-command-injection-from-environment.js#L6-L6)
1816

19-
<pre><code class="javascript">
20-
(function() {
17+
<pre><code class="javascript">(function() {
2118
cp.execFileSync('rm', ['-rf', path.join(__dirname, "temp")]); // GOOD
2219
cp.execSync(<strong>'rm -rf ' + path.join(__dirname, "temp")</strong>); // BAD
2320

2421
execa.shell('rm -rf ' + path.join(__dirname, "temp")); // NOT OK
25-
2622
</code></pre>
2723

2824
*This shell command depends on an uncontrolled [absolute path](https://github.com/github/codeql/blob/48015e5a2e6202131f2d1062cc066dc33ed69a9b/javascript/ql/test/query-tests/Security/CWE-078/tst_shell-command-injection-from-environment.js#L6-L6).*
@@ -31,13 +27,11 @@ function cleanupTemp() {
3127

3228
[javascript/ql/test/query-tests/Security/CWE-078/tst_shell-command-injection-from-environment.js](https://github.com/github/codeql/blob/48015e5a2e6202131f2d1062cc066dc33ed69a9b/javascript/ql/test/query-tests/Security/CWE-078/tst_shell-command-injection-from-environment.js#L8-L8)
3329

34-
<pre><code class="javascript">
35-
cp.execSync('rm -rf ' + path.join(__dirname, "temp")); // BAD
30+
<pre><code class="javascript"> cp.execSync('rm -rf ' + path.join(__dirname, "temp")); // BAD
3631

3732
execa.shell(<strong>'rm -rf ' + path.join(__dirname, "temp")</strong>); // NOT OK
3833
execa.shellSync('rm -rf ' + path.join(__dirname, "temp")); // NOT OK
3934

40-
4135
</code></pre>
4236

4337
*This shell command depends on an uncontrolled [absolute path](https://github.com/github/codeql/blob/48015e5a2e6202131f2d1062cc066dc33ed69a9b/javascript/ql/test/query-tests/Security/CWE-078/tst_shell-command-injection-from-environment.js#L8-L8).*
@@ -47,12 +41,10 @@ function cleanupTemp() {
4741
[javascript/ql/test/query-tests/Security/CWE-078/tst_shell-command-injection-from-environment.js](https://github.com/github/codeql/blob/48015e5a2e6202131f2d1062cc066dc33ed69a9b/javascript/ql/test/query-tests/Security/CWE-078/tst_shell-command-injection-from-environment.js#L9-L9)
4842

4943
<pre><code class="javascript">
50-
5144
execa.shell('rm -rf ' + path.join(__dirname, "temp")); // NOT OK
5245
execa.shellSync(<strong>'rm -rf ' + path.join(__dirname, "temp")</strong>); // NOT OK
5346

5447
const safe = "\"" + path.join(__dirname, "temp") + "\"";
55-
5648
</code></pre>
5749

5850
*This shell command depends on an uncontrolled [absolute path](https://github.com/github/codeql/blob/48015e5a2e6202131f2d1062cc066dc33ed69a9b/javascript/ql/test/query-tests/Security/CWE-078/tst_shell-command-injection-from-environment.js#L9-L9).*

extensions/ql-vscode/test/pure-tests/remote-queries/markdown-generation/data/interpreted-results/path-problem/results-repo2.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,11 @@
22

33
[npm-packages/meteor-installer/install.js](https://github.com/meteor/meteor/blob/73b538fe201cbfe89dd0c709689023f9b3eab1ec/npm-packages/meteor-installer/install.js#L259-L259)
44

5-
<pre><code class="javascript">
6-
if (isWindows()) {
5+
<pre><code class="javascript"> if (isWindows()) {
76
//set for the current session and beyond
87
child_process.execSync(<strong>`setx path "${meteorPath}/;%path%`</strong>);
98
return;
109
}
11-
1210
</code></pre>
1311

1412
*This shell command depends on an uncontrolled [absolute path](https://github.com/meteor/meteor/blob/73b538fe201cbfe89dd0c709689023f9b3eab1ec/npm-packages/meteor-installer/config.js#L39-L39).*

extensions/ql-vscode/test/pure-tests/remote-queries/markdown-generation/data/interpreted-results/problem/results-repo1.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,13 @@
33
[javascript/extractor/tests/regexp/input/multipart.js](https://github.com/github/codeql/blob/d094bbc06d063d0da8d0303676943c345e61de53/javascript/extractor/tests/regexp/input/multipart.js#L17-L20)
44

55
<pre><code class="javascript">
6-
76
var bad95 = new RegExp(
87
"<strong>(a" + </strong>
98
<strong> "|" + </strong>
109
<strong> "aa)*" + </strong>
1110
<strong> "</strong>b$"
1211
);
1312

14-
1513
</code></pre>
1614

1715
*This part of the regular expression may cause exponential backtracking on strings containing many repetitions of 'aa'.*

extensions/ql-vscode/test/pure-tests/remote-queries/markdown-generation/data/interpreted-results/problem/results-repo2.md

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,11 @@
22

33
[packages/deprecated/markdown/showdown.js](https://github.com/meteor/meteor/blob/53f3c4442d3542d3d2a012a854472a0d1bef9d12/packages/deprecated/markdown/showdown.js#L415-L415)
44

5-
<pre><code class="javascript">
6-
/g,hashElement);
5+
<pre><code class="javascript"> /g,hashElement);
76
*/
87
text = text.replace(/(\n\n[ ]{0,3}<!(--<strong>[^\r]*?</strong>--\s*)+>[ \t]*(?=\n{2,}))/g,hashElement);
98

109
// PHP and ASP-style processor instructions (<?...?> and <%...%>)
11-
1210
</code></pre>
1311

1412
*This part of the regular expression may cause exponential backtracking on strings containing many repetitions of '----'.*
@@ -17,13 +15,11 @@
1715

1816
[packages/deprecated/markdown/showdown.js](https://github.com/meteor/meteor/blob/53f3c4442d3542d3d2a012a854472a0d1bef9d12/packages/deprecated/markdown/showdown.js#L523-L523)
1917

20-
<pre><code class="javascript">
21-
// Build a regex to find HTML tags and comments. See Friedl's
18+
<pre><code class="javascript"> // Build a regex to find HTML tags and comments. See Friedl's
2219
// "Mastering Regular Expressions", 2nd Ed., pp. 200-201.
2320
var regex = /(<[a-z\/!$]("[^"]*"|'[^']*'|[^'">])*>|<!(--<strong>.*?</strong>--\s*)+>)/gi;
2421

2522
text = text.replace(regex, function(wholeMatch) {
26-
2723
</code></pre>
2824

2925
*This part of the regular expression may cause exponential backtracking on strings starting with '<!--' and containing many repetitions of '----'.*
@@ -32,13 +28,11 @@
3228

3329
[tools/tests/apps/modules/imports/links/acorn/src/parseutil.js](https://github.com/meteor/meteor/blob/53f3c4442d3542d3d2a012a854472a0d1bef9d12/tools/tests/apps/modules/imports/links/acorn/src/parseutil.js#L9-L9)
3430

35-
<pre><code class="javascript">
36-
// ## Parser utilities
31+
<pre><code class="javascript">// ## Parser utilities
3732

3833
const literal = /^(?:'(<strong>(?:\\.|[^'])*?</strong>)'|"((?:\\.|[^"])*?)")/
3934
pp.strictDirective = function(start) {
4035
for (;;) {
41-
4236
</code></pre>
4337

4438
*This part of the regular expression may cause exponential backtracking on strings starting with ''' and containing many repetitions of '\&'.*
@@ -47,13 +41,11 @@ pp.strictDirective = function(start) {
4741

4842
[tools/tests/apps/modules/imports/links/acorn/src/parseutil.js](https://github.com/meteor/meteor/blob/53f3c4442d3542d3d2a012a854472a0d1bef9d12/tools/tests/apps/modules/imports/links/acorn/src/parseutil.js#L9-L9)
4943

50-
<pre><code class="javascript">
51-
// ## Parser utilities
44+
<pre><code class="javascript">// ## Parser utilities
5245

5346
const literal = /^(?:'((?:\\.|[^'])*?)'|"(<strong>(?:\\.|[^"])*?</strong>)")/
5447
pp.strictDirective = function(start) {
5548
for (;;) {
56-
5749
</code></pre>
5850

5951
*This part of the regular expression may cause exponential backtracking on strings starting with '"' and containing many repetitions of '\!'.*

0 commit comments

Comments
 (0)