Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit d6deefe

Browse files
author
Max Schaefer
committed
JavaScript: Accept CDATA in E4X content.
1 parent 81b86d9 commit d6deefe

3 files changed

Lines changed: 657 additions & 639 deletions

File tree

javascript/extractor/src/com/semmle/jcorn/CustomParser.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -564,7 +564,7 @@ protected Token readToken(int code) {
564564

565565
@Override
566566
protected Either<Integer, Token> jsx_readChunk(StringBuilder out, int chunkStart, int ch) {
567-
// skip XML comments and processing instructions (which are allowed in E4X, but not in JSX)
567+
// skip XML comments, processing instructions and CDATA (which are allowed in E4X, but not in JSX)
568568
if (this.options.e4x() && ch == '<') {
569569
if (inputSubstring(this.pos+1, this.pos+4).equals("!--")) {
570570
out.append(inputSubstring(chunkStart, this.pos));
@@ -576,6 +576,13 @@ protected Either<Integer, Token> jsx_readChunk(StringBuilder out, int chunkStart
576576
this.pos += 2;
577577
jsx_readUntil("?>");
578578
return Either.left(this.pos);
579+
} else if (inputSubstring(this.pos+1, this.pos+9).equals("![CDATA[")) {
580+
out.append(inputSubstring(chunkStart, this.pos));
581+
this.pos += 9;
582+
int cdataStart = this.pos;
583+
jsx_readUntil("]]>");
584+
out.append(inputSubstring(cdataStart, this.pos-3));
585+
return Either.left(this.pos);
579586
}
580587
}
581588

javascript/extractor/tests/e4x/input/tst.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,5 @@ message.soap::[g()];
99

1010
var e = <?xml version="1.0" encoding="UTF-8"?> <elt>
1111
<!-- comment -->
12+
<![CDATA[ some <cdata> ]]>
1213
</elt>;

0 commit comments

Comments
 (0)