Skip to content
This repository was archived by the owner on Apr 22, 2020. It is now read-only.

Commit 3b9588d

Browse files
author
mikesamuel
committed
make sure it doesn't loop infinitely on empty tags
1 parent 9955697 commit 3b9588d

File tree

2 files changed

+16
-21
lines changed

2 files changed

+16
-21
lines changed

src/prettify.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1308,6 +1308,7 @@ function prettyPrint() {
13081308
// fetch the content as a snippet of properly escaped HTML.
13091309
// Firefox adds newlines at the end.
13101310
var content = cs.innerHTML.replace(/(?:\r\n?|\n)$/, '');
1311+
if (!content) { continue; }
13111312
if (isRawContent) {
13121313
content = PR_textToHtml(content);
13131314
}

tests/prettify_test.html

Lines changed: 15 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -17,23 +17,20 @@ <h1>Bash</h1>
1717
<pre class="prettyprint" id="bash">#!/bin/bash
1818

1919
# Fibonacci numbers
20-
# param int n >= 0
21-
# returns int >= 0
20+
# Writes an infinite series to stdout, one entry per line
2221
function fib() {
23-
local n=$(( $1 + 0 ))
24-
shift
2522
local a=1
2623
local b=1
27-
while [ "$n" != 0 ] ; do
24+
while true ; do
25+
echo $a
2826
local tmp=$a
2927
a=$(( $a + $b ))
3028
b=$tmp
31-
n=$(( $n - 1 ))
3229
done
33-
echo -n $a
3430
}
3531

36-
fib 10
32+
# output the 10th element of the series and halt
33+
fib | head -10 | tail -1
3734
</pre>
3835

3936
<h1>C</h1>
@@ -293,6 +290,9 @@ <h1>HTML using XMP</h1>
293290
</html>
294291
</xmp>
295292

293+
<h1>Whitespace</h1>
294+
<pre class=prettyprint id="whitespace"></pre>
295+
296296
</body>
297297

298298
<script type="text/javascript">
@@ -306,28 +306,21 @@ <h1>HTML using XMP</h1>
306306
'`COM#!/bin/bash`END`PLN<br>' +
307307
'<br>' +
308308
'`END`COM# Fibonacci numbers`END`PLN<br>' +
309-
'`END`COM# param int n &gt;= 0`END`PLN<br>' +
310-
'`END`COM# returns int &gt;= 0`END`PLN<br>' +
309+
'`END`COM# Writes an infinite series to stdout, one entry per line`END`PLN<br>' +
311310
'`END`KWDfunction`END`PLN fib`END`PUN()`END`PLN `END`PUN{`END`PLN<br>' +
312-
'&nbsp; local n`END`PUN=`END`PLN$`END`PUN((`END`PLN $1 `END`PUN+' +
313-
'`END`PLN `END`LIT0`END`PLN `END`PUN))`END`PLN<br>' +
314-
'&nbsp; shift<br>' +
315311
'&nbsp; local a`END`PUN=`END`LIT1`END`PLN<br>' +
316312
'&nbsp; local b`END`PUN=`END`LIT1`END`PLN<br>' +
317-
'&nbsp; `END`KWDwhile`END`PLN `END`PUN[`END`PLN `END`STR"$n"`END' +
318-
'`PLN `END`PUN!=`END`PLN `END`LIT0`END`PLN `END`PUN]`END`PLN `END' +
319-
'`PUN;`END`PLN `END`KWDdo`END`PLN<br>' +
313+
'&nbsp; `END`KWDwhile`END`PLN `END`KWDtrue`END`PLN `END`PUN;`END`PLN `END`KWDdo`END`PLN<br>' +
314+
'&nbsp; &nbsp; echo $a<br>' +
320315
'&nbsp; &nbsp; local tmp`END`PUN=`END`PLN$a<br>' +
321316
'&nbsp; &nbsp; a`END`PUN=`END`PLN$`END`PUN((`END`PLN $a `END`PUN+`END' +
322317
'`PLN $b `END`PUN))`END`PLN<br>' +
323318
'&nbsp; &nbsp; b`END`PUN=`END`PLN$tmp<br>' +
324-
'&nbsp; &nbsp; n`END`PUN=`END`PLN$`END`PUN((`END`PLN $n `END`PUN-`END' +
325-
'`PLN `END`LIT1`END`PLN `END`PUN))`END`PLN<br>' +
326319
'&nbsp; done<br>' +
327-
'&nbsp; echo `END`PUN-`END`PLNn $a<br>' +
328320
'`END`PUN}`END`PLN<br>' +
329321
'<br>' +
330-
'fib `END`LIT10`END'),
322+
'`END`COM# output the 10th element of the series and halt`END`PLN<br>' +
323+
'fib `END`PUN|`END`PLN head `END`PUN-`END`LIT10`END`PLN `END`PUN|`END`PLN tail `END`PUN-`END`LIT1`END'),
331324

332325
C: (
333326
'`COM#include &lt;stdio.h&gt;`END`PLN<br>' +
@@ -668,7 +661,8 @@ <h1>HTML using XMP</h1>
668661
'`END`COM// --&gt;`END`PLN<br>' +
669662
'&nbsp; &nbsp; `END`END`TAG&lt;/script&gt;`END`PLN<br>' +
670663
'&nbsp; `END`TAG&lt;/body&gt;`END`PLN<br>' +
671-
'`END`TAG&lt;/html&gt;`END')
664+
'`END`TAG&lt;/html&gt;`END'),
665+
whitespace: ''
672666
};
673667

674668

0 commit comments

Comments
 (0)