Skip to content

Commit df106d9

Browse files
committed
Fix dangling JSON span by subclassing JFlexXrefSimple
Also: - Make JsonXref case-sensitive, revising {File} to match any case. - Escape all HTML special characters in JsonXref. - Use Common.xref in JsonSymbolTokenizer.
1 parent 7f9a560 commit df106d9

File tree

5 files changed

+89
-54
lines changed

5 files changed

+89
-54
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/*
2+
* CDDL HEADER START
3+
*
4+
* The contents of this file are subject to the terms of the
5+
* Common Development and Distribution License (the "License").
6+
* You may not use this file except in compliance with the License.
7+
*
8+
* See LICENSE.txt included in this distribution for the specific
9+
* language governing permissions and limitations under the License.
10+
*
11+
* When distributing Covered Code, include this CDDL HEADER in each
12+
* file and include the License file at LICENSE.txt.
13+
* If applicable, add the following below this CDDL HEADER, with the
14+
* fields enclosed by brackets "[]" replaced with your own identifying
15+
* information: Portions Copyright [yyyy] [name of copyright owner]
16+
*
17+
* CDDL HEADER END
18+
*/
19+
20+
/*
21+
* Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
22+
* Portions Copyright (c) 2017, Chris Fraire <[email protected]>.
23+
*/
24+
25+
/*
26+
* TODO add unicode support
27+
*/
28+
Identifier = [a-zA-Z_$] [a-zA-Z0-9_$]*
29+
30+
Number = (0[xX][0-9a-fA-F]+|[0-9]+\.[0-9]+|[0-9]+)(([eE][+-]?[0-9]+)?[ufdlUFDL]*)?

src/org/opensolaris/opengrok/analysis/json/JsonSymbolTokenizer.lex

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -44,32 +44,30 @@ super(in);
4444
%include CommonTokenizer.lexh
4545
%char
4646

47-
/* TODO : add unicode support */
48-
Identifier = [a-zA-Z_$] [a-zA-Z0-9_$]*
49-
50-
Number = (0[xX][0-9a-fA-F]+|[0-9]+\.[0-9]+|[0-9]+)(([eE][+-]?[0-9]+)?[ufdlUFDL]*)?
51-
5247
%state STRING
5348

49+
%include Json.lexh
5450
%%
5551

5652
//TODO improve per http://www.ecma-international.org/publications/files/ECMA-ST/ECMA-404.pdf
5753

5854
<YYINITIAL> {
59-
{Identifier} {String id = yytext();
55+
{Identifier} {
56+
String id = yytext();
6057
if(!Consts.kwd.contains(id)){
6158
setAttribs(id, yychar, yychar + yylength());
62-
return yystate(); }
63-
}
59+
return yystate();
60+
}
61+
}
6462

65-
{Number} {}
63+
{Number} {}
6664

6765
\" { yybegin(STRING); }
6866
}
6967

7068
<STRING> {
69+
\\[\"\\] {}
7170
\" { yybegin(YYINITIAL); }
72-
\\\\ | \\\" {}
7371
}
7472

7573
<YYINITIAL, STRING> {

src/org/opensolaris/opengrok/analysis/json/JsonXref.lex

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -27,18 +27,18 @@
2727
*/
2828

2929
package org.opensolaris.opengrok.analysis.json;
30-
import org.opensolaris.opengrok.analysis.JFlexXref;
30+
import org.opensolaris.opengrok.analysis.JFlexXrefSimple;
3131
import java.io.IOException;
3232
import java.io.Writer;
3333
import java.io.Reader;
34+
import org.opensolaris.opengrok.web.HtmlConsts;
3435
import org.opensolaris.opengrok.web.Util;
3536

3637
%%
3738
%public
3839
%class JsonXref
39-
%extends JFlexXref
40+
%extends JFlexXrefSimple
4041
%unicode
41-
%ignorecase
4242
%int
4343
%include CommonXref.lexh
4444
%{
@@ -49,18 +49,17 @@ import org.opensolaris.opengrok.web.Util;
4949
protected void setLineNumber(int x) { yyline = x; }
5050
%}
5151

52-
//TODO add unicode support
53-
Identifier = [a-zA-Z_$] [a-zA-Z0-9_$]+
54-
55-
File = [a-zA-Z]{FNameChar}* "." ("js"|"properties"|"props"|"xml"|"conf"|"txt"|"htm"|"html"|"ini"|"diff"|"patch")
56-
57-
Number = (0[xX][0-9a-fA-F]+|[0-9]+\.[0-9]+|[0-9]+)(([eE][+-]?[0-9]+)?[ufdlUFDL]*)?
52+
File = [a-zA-Z]{FNameChar}* "." ([Jj][Ss] |
53+
[Pp][Rr][Oo][Pp][Ee][Rr][Tt][Ii][Ee][Ss] | [Pp][Rr][Oo][Pp][Ss] |
54+
[Xx][Mm][Ll] | [Cc][Oo][Nn][Ff] | [Tt][Xx][Tt] | [Hh][Tt][Mm] |
55+
[Hh][Tt][Mm][Ll]? | [Ii][Nn][Ii] | [Dd][Ii][Ff][Ff] | [Pp][Aa][Tt][Cc][Hh])
5856

5957
%state STRING
6058

6159
%include Common.lexh
6260
%include CommonURI.lexh
6361
%include CommonPath.lexh
62+
%include Json.lexh
6463
%%
6564
<YYINITIAL>{
6665

@@ -89,22 +88,30 @@ Number = (0[xX][0-9a-fA-F]+|[0-9]+\.[0-9]+|[0-9]+)(([eE][+-]?[0-9]+)?[ufdlUFDL]*
8988
{ out.write(Util.breadcrumbPath(urlPrefix+"defs=",yytext(),'.'));}
9089
*/
9190

92-
{Number} { out.write("<span class=\"n\">"); out.write(yytext()); out.write("</span>"); }
91+
{Number} {
92+
disjointSpan(HtmlConsts.NUMBER_CLASS);
93+
out.write(yytext());
94+
disjointSpan(null);
95+
}
9396

94-
\" { yybegin(STRING);out.write("<span class=\"s\">\"");}
97+
\" {
98+
pushSpan(STRING, HtmlConsts.STRING_CLASS);
99+
out.write(htmlize(yytext()));
100+
}
95101
}
96102

97103
<STRING> {
98-
\" {WhiteSpace} \" { out.write(yytext());}
99-
\" { yybegin(YYINITIAL); out.write("\"</span>"); }
100-
\\\\ { out.write("\\\\"); }
101-
\\\" { out.write("\\\""); }
104+
\\[\"\\] |
105+
\" {WhiteSpace} \" { out.write(htmlize(yytext())); }
106+
\" {
107+
out.write(htmlize(yytext()));
108+
yypop();
109+
}
102110
}
103111

104112
<YYINITIAL, STRING> {
105-
"&" {out.write( "&amp;");}
106-
"<" {out.write( "&lt;");}
107-
">" {out.write( "&gt;");}
113+
[&<>\'\"] { out.write(htmlize(yytext())); }
114+
108115
{WhspChar}*{EOL} { startNewLine(); }
109116
{WhiteSpace} { out.write(yytext()); }
110117
[!-~] { out.write(yycharat(0)); }

test/org/opensolaris/opengrok/analysis/json/sample_xref.html

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -7,31 +7,31 @@
77
<title>sampleFile - OpenGrok cross reference for /sampleFile</title></head><body>
88
<script type="text/javascript">/* <![CDATA[ */
99
function get_sym_list(){return [];} /* ]]> */</script><a class="l" name="1" href="#1">1</a>{
10-
<a class="l" name="2" href="#2">2</a> <span class="s">"lic01"</span> : <span class="s">"CDDL HEADER START"</span>,
11-
<a class="l" name="3" href="#3">3</a> <span class="s">"lic02"</span> : <span class="s">""</span>,
12-
<a class="l" name="4" href="#4">4</a> <span class="s">"lic03"</span> : <span class="s">"The contents of this file are subject to the terms of the"</span>,
13-
<a class="l" name="5" href="#5">5</a> <span class="s">"lic04"</span> : <span class="s">"Common Development and Distribution License (the \"License\")."</span>,
14-
<a class="l" name="6" href="#6">6</a> <span class="s">"lic05"</span> : <span class="s">"You may not use this file except in compliance with the License."</span>,
15-
<a class="l" name="7" href="#7">7</a> <span class="s">"lic06"</span> : <span class="s">""</span>,
16-
<a class="l" name="8" href="#8">8</a> <span class="s">"lic07"</span> : <span class="s">"See <a href="/source/s?path=LICENSE.txt">LICENSE.txt</a> included in this distribution for the specific"</span>,
17-
<a class="l" name="9" href="#9">9</a> <span class="s">"lic08"</span> : <span class="s">"language governing permissions and limitations under the License."</span>,
18-
<a class="hl" name="10" href="#10">10</a> <span class="s">"lic09"</span> : <span class="s">""</span>,
19-
<a class="l" name="11" href="#11">11</a> <span class="s">"lic10"</span> : <span class="s">"When distributing Covered Code, include this CDDL HEADER in each"</span>,
20-
<a class="l" name="12" href="#12">12</a> <span class="s">"lic11"</span> : <span class="s">"file and include the License file at <a href="/source/s?path=LICENSE.txt">LICENSE.txt</a>."</span>,
21-
<a class="l" name="13" href="#13">13</a> <span class="s">"lic12"</span> : <span class="s">"If applicable, add the following below this CDDL HEADER, with the"</span>,
22-
<a class="l" name="14" href="#14">14</a> <span class="s">"lic13"</span> : <span class="s">"fields enclosed by brackets \"[]\" replaced with your own identifying"</span>,
23-
<a class="l" name="15" href="#15">15</a> <span class="s">"lic14"</span> : <span class="s">"information: Portions Copyright [yyyy] [name of copyright owner]"</span>,
24-
<a class="l" name="16" href="#16">16</a> <span class="s">"lic15"</span> : <span class="s">""</span>,
25-
<a class="l" name="17" href="#17">17</a> <span class="s">"lic16"</span> : <span class="s">"CDDL HEADER END"</span>,
26-
<a class="l" name="18" href="#18">18</a> <span class="s">"spc01"</span> : <b>null</b>,
27-
<a class="l" name="19" href="#19">19</a> <span class="s">"cpy01"</span> : <span class="s">"Copyright (c) 2017, Chris Fraire &lt;[email protected]&gt;."</span>,
28-
<a class="hl" name="20" href="#20">20</a> <span class="s">"strings"</span> : [<span class="s">"\u002F"</span>, <span class="s">"\u002f"</span>, <span class="s">"\/"</span>, <span class="s">"/"</span>, <span class="s">"\uD834\uDD1E"</span>, <span class="s">"\""</span>, <span class="s">"\'"</span>,
29-
<a class="l" name="21" href="#21">21</a> <span class="s">"\\"</span>],
30-
<a class="l" name="22" href="#22">22</a> <span class="s">"spc02"</span> : <b>null</b>,
31-
<a class="l" name="23" href="#23">23</a> <span class="s">"numbers"</span> : [ <span class="n">0</span>, -<span class="n">1</span>, <span class="n">1.2</span>, -<span class="n">2.4</span>, -<span class="n">1e5</span>, <span class="n">1e-6</span>, <span class="n">20.5e97</span>, -<span class="n">33.2e-4</span> ],
32-
<a class="l" name="24" href="#24">24</a> <span class="s">"spc03"</span> : <b>null</b>,
33-
<a class="l" name="25" href="#25">25</a> <span class="s">"booleans"</span> : [ <b>true</b>, <b>false</b> ],
34-
<a class="l" name="26" href="#26">26</a> <span class="s">"END"</span> : <span class="s">""</span>
10+
<a class="l" name="2" href="#2">2</a> <span class="s">&quot;lic01&quot;</span> : <span class="s">&quot;CDDL HEADER START&quot;</span>,
11+
<a class="l" name="3" href="#3">3</a> <span class="s">&quot;lic02&quot;</span> : <span class="s">&quot;&quot;</span>,
12+
<a class="l" name="4" href="#4">4</a> <span class="s">&quot;lic03&quot;</span> : <span class="s">&quot;The contents of this file are subject to the terms of the&quot;</span>,
13+
<a class="l" name="5" href="#5">5</a> <span class="s">&quot;lic04&quot;</span> : <span class="s">&quot;Common Development and Distribution License (the \&quot;License\&quot;).&quot;</span>,
14+
<a class="l" name="6" href="#6">6</a> <span class="s">&quot;lic05&quot;</span> : <span class="s">&quot;You may not use this file except in compliance with the License.&quot;</span>,
15+
<a class="l" name="7" href="#7">7</a> <span class="s">&quot;lic06&quot;</span> : <span class="s">&quot;&quot;</span>,
16+
<a class="l" name="8" href="#8">8</a> <span class="s">&quot;lic07&quot;</span> : <span class="s">&quot;See <a href="/source/s?path=LICENSE.txt">LICENSE.txt</a> included in this distribution for the specific&quot;</span>,
17+
<a class="l" name="9" href="#9">9</a> <span class="s">&quot;lic08&quot;</span> : <span class="s">&quot;language governing permissions and limitations under the License.&quot;</span>,
18+
<a class="hl" name="10" href="#10">10</a> <span class="s">&quot;lic09&quot;</span> : <span class="s">&quot;&quot;</span>,
19+
<a class="l" name="11" href="#11">11</a> <span class="s">&quot;lic10&quot;</span> : <span class="s">&quot;When distributing Covered Code, include this CDDL HEADER in each&quot;</span>,
20+
<a class="l" name="12" href="#12">12</a> <span class="s">&quot;lic11&quot;</span> : <span class="s">&quot;file and include the License file at <a href="/source/s?path=LICENSE.txt">LICENSE.txt</a>.&quot;</span>,
21+
<a class="l" name="13" href="#13">13</a> <span class="s">&quot;lic12&quot;</span> : <span class="s">&quot;If applicable, add the following below this CDDL HEADER, with the&quot;</span>,
22+
<a class="l" name="14" href="#14">14</a> <span class="s">&quot;lic13&quot;</span> : <span class="s">&quot;fields enclosed by brackets \&quot;[]\&quot; replaced with your own identifying&quot;</span>,
23+
<a class="l" name="15" href="#15">15</a> <span class="s">&quot;lic14&quot;</span> : <span class="s">&quot;information: Portions Copyright [yyyy] [name of copyright owner]&quot;</span>,
24+
<a class="l" name="16" href="#16">16</a> <span class="s">&quot;lic15&quot;</span> : <span class="s">&quot;&quot;</span>,
25+
<a class="l" name="17" href="#17">17</a> <span class="s">&quot;lic16&quot;</span> : <span class="s">&quot;CDDL HEADER END&quot;</span>,
26+
<a class="l" name="18" href="#18">18</a> <span class="s">&quot;spc01&quot;</span> : <b>null</b>,
27+
<a class="l" name="19" href="#19">19</a> <span class="s">&quot;cpy01&quot;</span> : <span class="s">&quot;Copyright (c) 2017, Chris Fraire &lt;[email protected]&gt;.&quot;</span>,
28+
<a class="hl" name="20" href="#20">20</a> <span class="s">&quot;strings&quot;</span> : [<span class="s">&quot;\u002F&quot;</span>, <span class="s">&quot;\u002f&quot;</span>, <span class="s">&quot;\/&quot;</span>, <span class="s">&quot;/&quot;</span>, <span class="s">&quot;\uD834\uDD1E&quot;</span>, <span class="s">&quot;\&quot;&quot;</span>, <span class="s">&quot;\&apos;&quot;</span>,
29+
<a class="l" name="21" href="#21">21</a> <span class="s">&quot;\\&quot;</span>],
30+
<a class="l" name="22" href="#22">22</a> <span class="s">&quot;spc02&quot;</span> : <b>null</b>,
31+
<a class="l" name="23" href="#23">23</a> <span class="s">&quot;numbers&quot;</span> : [ <span class="n">0</span>, -<span class="n">1</span>, <span class="n">1.2</span>, -<span class="n">2.4</span>, -<span class="n">1e5</span>, <span class="n">1e-6</span>, <span class="n">20.5e97</span>, -<span class="n">33.2e-4</span> ],
32+
<a class="l" name="24" href="#24">24</a> <span class="s">&quot;spc03&quot;</span> : <b>null</b>,
33+
<a class="l" name="25" href="#25">25</a> <span class="s">&quot;booleans&quot;</span> : [ <b>true</b>, <b>false</b> ],
34+
<a class="l" name="26" href="#26">26</a> <span class="s">&quot;END&quot;</span> : <span class="s">&quot;&quot;</span>
3535
<a class="l" name="27" href="#27">27</a>}
3636
<a class="l" name="28" href="#28">28</a></body>
3737
</html>

test/org/opensolaris/opengrok/analysis/json/truncated_xref.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@
55
class="xref">
66
<head>
77
<title>sampleFile - OpenGrok cross reference for /sampleFile</title></head><body>
8-
<a class="l" name="1" href="#1">1</a> <span class="s">"Oops this string is not ter</span></body>
8+
<a class="l" name="1" href="#1">1</a> <span class="s">&quot;Oops this string is not ter</span></body>
99
</html>

0 commit comments

Comments
 (0)