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

Commit 8068cdf

Browse files
author
mikesamuel
committed
fixed issue 4
recursing into a script block or PHP tag that was not properly closed would not silently drop the content.
1 parent b284777 commit 8068cdf

File tree

1 file changed

+20
-6
lines changed

1 file changed

+20
-6
lines changed

src/prettify.js

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -976,11 +976,21 @@ function PR_splitSourceNodes(tokens) {
976976

977977
var sourceChunks = null;
978978

979-
for (var ci = 0, nc = tokens.length; ci < nc; ++ci) {
980-
var tok = tokens[ci];
981-
if (null == tok.style) {
982-
tokens.push(tok);
983-
continue;
979+
for (var ci = 0, nc = tokens.length; /* break below */; ++ci) {
980+
var tok;
981+
982+
if (ci < nc) {
983+
tok = tokens[ci];
984+
if (null == tok.style) {
985+
tokens.push(tok);
986+
continue;
987+
}
988+
} else if (!endScriptTag) {
989+
break;
990+
} else {
991+
// else pretend there's an end tag so we can gracefully handle
992+
// unclosed source blocks
993+
tok = new PR_Token('', null);
984994
}
985995

986996
var s = tok.token;
@@ -1038,6 +1048,9 @@ function PR_splitSourceNodes(tokens) {
10381048
} else {
10391049
tokensOut.push(tok);
10401050
}
1051+
} else if (ci >= nc) {
1052+
// force the token to close
1053+
endTok = tok;
10411054
} else {
10421055
if (sourceChunks) {
10431056
sourceChunks.push(tok);
@@ -1056,7 +1069,7 @@ function PR_splitSourceNodes(tokens) {
10561069
tokensOut.push(new PR_Token('</span>', null));
10571070
sourceChunks = null;
10581071
}
1059-
tokensOut.push(endTok);
1072+
if (endTok.token) { tokensOut.push(endTok); }
10601073
endScriptTag = null;
10611074
}
10621075
} else {
@@ -1278,6 +1291,7 @@ function PR_lexOne(s) {
12781291
break;
12791292
}
12801293
}
1294+
12811295
return isMarkup ? PR_lexMarkup(chunks) : PR_lexSource(chunks);
12821296
}
12831297

0 commit comments

Comments
 (0)