Skip to content

Commit e286327

Browse files
committed
Fix dangling JavaScript span. Fix to fine-tune URI link.
Also: - Fix to fine-tune URI link for JavaScript QSTRING,LQSTRING. - Make JavaScriptXref case-sensitive, revising {File} to match any case. - Escape all HTML special characters in JavaScriptXref. - Use Common.xref in JavaScriptSymbolTokenizer.
1 parent 23dbb34 commit e286327

File tree

3 files changed

+114
-86
lines changed

3 files changed

+114
-86
lines changed

src/org/opensolaris/opengrok/analysis/javascript/JavaScriptSymbolTokenizer.lex

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,8 @@
2727
*/
2828

2929
package org.opensolaris.opengrok.analysis.javascript;
30-
import java.io.IOException;
31-
import java.io.Reader;
32-
import org.opensolaris.opengrok.analysis.JFlexTokenizer;
3330

31+
import org.opensolaris.opengrok.analysis.JFlexTokenizer;
3432
%%
3533
%public
3634
%class JavaScriptSymbolTokenizer
@@ -63,11 +61,12 @@ super(in);
6361
}
6462

6563
<STRING> {
64+
\\[\"\\] {}
6665
\" { yybegin(YYINITIAL); }
67-
\\\\ | \\\" {}
6866
}
6967

7068
<QSTRING> {
69+
\\[\'\\] {}
7170
\' { yybegin(YYINITIAL); }
7271
}
7372

src/org/opensolaris/opengrok/analysis/javascript/JavaScriptXref.lex

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

2929
package org.opensolaris.opengrok.analysis.javascript;
30-
import org.opensolaris.opengrok.analysis.JFlexXref;
31-
import java.io.IOException;
32-
import java.io.Writer;
33-
import java.io.Reader;
34-
import org.opensolaris.opengrok.web.Util;
3530

31+
import org.opensolaris.opengrok.analysis.JFlexXrefSimple;
32+
import org.opensolaris.opengrok.util.StringUtils;
33+
import org.opensolaris.opengrok.web.HtmlConsts;
34+
import org.opensolaris.opengrok.web.Util;
3635
%%
3736
%public
3837
%class JavaScriptXref
39-
%extends JFlexXref
38+
%extends JFlexXrefSimple
4039
%unicode
41-
%ignorecase
4240
%int
4341
%include CommonXref.lexh
4442
%{
@@ -49,7 +47,10 @@ import org.opensolaris.opengrok.web.Util;
4947
protected void setLineNumber(int x) { yyline = x; }
5048
%}
5149

52-
File = [a-zA-Z]{FNameChar}* "." ("js"|"properties"|"props"|"xml"|"conf"|"txt"|"htm"|"html"|"ini"|"diff"|"patch")
50+
File = [a-zA-Z]{FNameChar}* "." ([Jj][Ss] |
51+
[Pp][Rr][Oo][Pp][Ee][Rr][Tt][Ii][Ee][Ss] | [Pp][Rr][Oo][Pp][Ss] |
52+
[Xx][Mm][Ll] | [Cc][Oo][Nn][Ff] | [Tt][Xx][Tt] | [Hh][Tt][Mm][Ll]? |
53+
[Ii][Nn][Ii] | [Dd][Ii][Ff][Ff] | [Pp][Aa][Tt][Cc][Hh])
5354

5455
%state STRING COMMENT SCOMMENT QSTRING
5556

@@ -84,54 +85,68 @@ File = [a-zA-Z]{FNameChar}* "." ("js"|"properties"|"props"|"xml"|"conf"|"txt"|"h
8485
out.write("&gt;");
8586
}
8687

87-
/*
88-
{ out.write(Util.breadcrumbPath(urlPrefix+"defs=",yytext(),'.'));}
89-
*/
90-
{Number} { out.write("<span class=\"n\">"); out.write(yytext()); out.write("</span>"); }
91-
92-
\" { yybegin(STRING);out.write("<span class=\"s\">\"");}
93-
\' { yybegin(QSTRING);out.write("<span class=\"s\">\'");}
94-
"/*" { yybegin(COMMENT);out.write("<span class=\"c\">/*");}
95-
"//" { yybegin(SCOMMENT);out.write("<span class=\"c\">//");}
88+
{Number} {
89+
disjointSpan(HtmlConsts.NUMBER_CLASS);
90+
out.write(yytext());
91+
disjointSpan(null);
92+
}
93+
94+
\" {
95+
pushSpan(STRING, HtmlConsts.STRING_CLASS);
96+
out.write(htmlize(yytext()));
97+
}
98+
\' {
99+
pushSpan(QSTRING, HtmlConsts.STRING_CLASS);
100+
out.write(htmlize(yytext()));
101+
}
102+
"/*" {
103+
pushSpan(COMMENT, HtmlConsts.COMMENT_CLASS);
104+
out.write(yytext());
105+
}
106+
"//" {
107+
pushSpan(SCOMMENT, HtmlConsts.COMMENT_CLASS);
108+
out.write(yytext());
109+
}
96110
}
97111

98112
<STRING> {
99-
\" {WhiteSpace} \" { out.write(yytext());}
100-
\" { yybegin(YYINITIAL); out.write("\"</span>"); }
101-
\\\\ { out.write("\\\\"); }
102-
\\\" { out.write("\\\""); }
113+
\\[\"\\] |
114+
\" {WhiteSpace} \" { out.write(htmlize(yytext())); }
115+
\" {
116+
out.write(htmlize(yytext()));
117+
yypop();
118+
}
103119
}
104120

105121
<QSTRING> {
106-
"\\\\" { out.write("\\\\"); }
107-
"\\\'" { out.write("\\\'"); }
108-
\' {WhiteSpace} \' { out.write(yytext()); }
109-
\' { yybegin(YYINITIAL); out.write("'</span>"); }
122+
\\[\'\\] |
123+
\' {WhiteSpace} \' { out.write(htmlize(yytext())); }
124+
\' {
125+
out.write(htmlize(yytext()));
126+
yypop();
127+
}
110128
}
111129

112130
<COMMENT> {
113-
"*/" { yybegin(YYINITIAL); out.write("*/</span>"); }
131+
"*/" { out.write(yytext()); yypop(); }
114132
}
115133

116134
<SCOMMENT> {
117-
{WhspChar}*{EOL} {
118-
yybegin(YYINITIAL); out.write("</span>");
135+
{WhspChar}*{EOL} {
136+
yypop();
119137
startNewLine();
120138
}
121139
}
122140

123-
124141
<YYINITIAL, STRING, COMMENT, SCOMMENT, QSTRING> {
125-
"&" {out.write( "&amp;");}
126-
"<" {out.write( "&lt;");}
127-
">" {out.write( "&gt;");}
142+
[&<>\'\"] { out.write(htmlize(yytext())); }
128143
{WhspChar}*{EOL} { startNewLine(); }
129144
{WhiteSpace} { out.write(yytext()); }
130145
[!-~] { out.write(yycharat(0)); }
131146
[^\n] { writeUnicodeChar(yycharat(0)); }
132147
}
133148

134-
<STRING, COMMENT, SCOMMENT, STRING, QSTRING> {
149+
<STRING, COMMENT, SCOMMENT, QSTRING> {
135150
{FPath}
136151
{ out.write(Util.breadcrumbPath(urlPrefix+"path=",yytext(),'/'));}
137152

@@ -145,12 +160,26 @@ File = [a-zA-Z]{FNameChar}* "." ("js"|"properties"|"props"|"xml"|"conf"|"txt"|"h
145160
out.write(path);
146161
out.write("</a>");}
147162

148-
{BrowseableURI} {
149-
appendLink(yytext(), true);
150-
}
151-
152163
{FNameChar}+ "@" {FNameChar}+ "." {FNameChar}+
153164
{
154165
writeEMailAddress(yytext());
155166
}
156167
}
168+
169+
<STRING, SCOMMENT> {
170+
{BrowseableURI} {
171+
appendLink(yytext(), true);
172+
}
173+
}
174+
175+
<COMMENT> {
176+
{BrowseableURI} {
177+
appendLink(yytext(), true, StringUtils.END_C_COMMENT);
178+
}
179+
}
180+
181+
<QSTRING> {
182+
{BrowseableURI} {
183+
appendLink(yytext(), true, StringUtils.APOS_NO_BSESC);
184+
}
185+
}

0 commit comments

Comments
 (0)