Skip to content

Commit 2d10b85

Browse files
committed
Restore URL-in-sentences matching behavior
Previously with the {BrowseableURI} change, URLs ending in dots would not include the dot, even though the dot is a valid URI character. Restore this behavior with a new mode of appendLink().
1 parent ffba560 commit 2d10b85

35 files changed

+120
-32
lines changed

src/org/opensolaris/opengrok/analysis/JFlexXref.java

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
import org.opensolaris.opengrok.configuration.Project;
4343
import org.opensolaris.opengrok.configuration.RuntimeEnvironment;
4444
import org.opensolaris.opengrok.history.Annotation;
45+
import org.opensolaris.opengrok.util.StringUtils;
4546
import org.opensolaris.opengrok.web.Util;
4647

4748
/**
@@ -202,7 +203,41 @@ protected void appendProject() throws IOException {
202203
}
203204
}
204205

206+
/**
207+
* Calls {@link #appendLink(java.lang.String, boolean) with false to
208+
* disable {@code doPushback} handling.
209+
* @param url the URL to append
210+
* @throws IOException if an error occurs while appending
211+
*/
205212
protected void appendLink(String url) throws IOException {
213+
appendLink(url, false);
214+
}
215+
216+
/**
217+
* Appends the {@code url} to the active {@link Writer}. If
218+
* {@code doPushback} is true, then any characters counted by
219+
* {@link StringUtils#countURIEndingPushback(java.lang.String)} are
220+
* handled by {@link #yypushback(int)} with {@code url} only partially
221+
* written.
222+
* <p>If the count is equal to the length of {@code url}, then it is
223+
* simply written, and nothing is pushed back.
224+
* @param url the URL to append
225+
* @param doPushback a value indicating whether to test the {@code url}
226+
* with {@link StringUtils#countURIEndingPushback(java.lang.String)}.
227+
* @throws IOException if an error occurs while appending
228+
*/
229+
protected void appendLink(String url, boolean doPushback)
230+
throws IOException {
231+
232+
if (doPushback) {
233+
int n = StringUtils.countURIEndingPushback(url);
234+
// Push back if positive, but not if equal to the current length,
235+
// or else the pushback might cause a neverending loop.
236+
if (n > 0 && n < url.length()) {
237+
yypushback(n);
238+
url = url.substring(0, url.length() - n);
239+
}
240+
}
206241
out.write("<a href=\"");
207242
out.write(Util.formQuoteEscape(url));
208243
out.write("\">");
@@ -297,6 +332,14 @@ public Scopes getScopes() {
297332
*/
298333
public abstract void yybegin(int newState);
299334

335+
/**
336+
* Pushes {@code number} characters of the matched text back into the
337+
* input stream per the documented JFlex behavior.
338+
* @param number a value greater than or equal to zero and less than or
339+
* equal to the length of the matched text.
340+
*/
341+
public abstract void yypushback(int number);
342+
300343
/**
301344
* returns current state of analysis
302345
* @return id of state

src/org/opensolaris/opengrok/analysis/ada/AdaProductions.lexh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ File = [a-zA-Z]{FNameChar}* "." {FileExt}
223223

224224
{BrowseableURI} {
225225
if (takeAllContent()) {
226-
appendLink(yytext());
226+
appendLink(yytext(), true);
227227
}
228228
}
229229

src/org/opensolaris/opengrok/analysis/ada/AdaSymbolTokenizer.lex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ import org.opensolaris.opengrok.web.Util;
118118

119119
protected void appendProject() { /* noop */ }
120120

121-
protected void appendLink(String s) { /* noop */ }
121+
protected void appendLink(String s, boolean b) { /* noop */ }
122122

123123
protected void writeEMailAddress(String s) { /* noop */ }
124124
%}

src/org/opensolaris/opengrok/analysis/c/CXref.lex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ Number = (0[xX][0-9a-fA-F]+|[0-9]+\.[0-9]+|[1-9][0-9]*)(([eE][+-]?[0-9]+)?[ufdlU
149149
out.write("</a>");}
150150

151151
{BrowseableURI} {
152-
appendLink(yytext());
152+
appendLink(yytext(), true);
153153
}
154154

155155
{FNameChar}+ "@" {FNameChar}+ "." {FNameChar}+

src/org/opensolaris/opengrok/analysis/c/CxxXref.lex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ Number = (0[xX][0-9a-fA-F]+|[0-9]+\.[0-9]+|[1-9][0-9]*)(([eE][+-]?[0-9]+)?[ufdlU
146146
out.write("</a>");}
147147

148148
{BrowseableURI} {
149-
appendLink(yytext());
149+
appendLink(yytext(), true);
150150
}
151151

152152
{FNameChar}+ "@" {FNameChar}+ "." {FNameChar}+

src/org/opensolaris/opengrok/analysis/clojure/ClojureXref.lex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ Number = ([0-9]+\.[0-9]+|[0-9][0-9]*|"#" [boxBOX] [0-9a-fA-F]+)
138138
out.write("</a>");}
139139

140140
{BrowseableURI} {
141-
appendLink(yytext());
141+
appendLink(yytext(), true);
142142
}
143143

144144
{FNameChar}+ "@" {FNameChar}+ "." {FNameChar}+

src/org/opensolaris/opengrok/analysis/csharp/CSharpXref.lex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ Number = (0[xX][0-9a-fA-F]+|[0-9]+\.[0-9]+|[0-9]+)(([eE][+-]?[0-9]+)?[ufdlUFDL]*
158158
out.write("</a>");}
159159

160160
{BrowseableURI} {
161-
appendLink(yytext());
161+
appendLink(yytext(), true);
162162
}
163163

164164
{FNameChar}+ "@" {FNameChar}+ "." {FNameChar}+

src/org/opensolaris/opengrok/analysis/erlang/ErlangXref.lex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ Number = (0[xX][0-9a-fA-F]+|[0-9]+\.[0-9]+|[0-9]+)(([eE][+-]?[0-9]+)?[loxbLOXBjJ
146146
out.write("</a>");}
147147

148148
{BrowseableURI} {
149-
appendLink(yytext());
149+
appendLink(yytext(), true);
150150
}
151151

152152
{FNameChar}+ "@" {FNameChar}+ "." {FNameChar}+

src/org/opensolaris/opengrok/analysis/fortran/FortranXref.lex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ Number = ([0-9]+\.[0-9]+|[0-9][0-9]*|"0x" [0-9a-fA-F]+ )([udl]+)?
151151
out.write(path);out.write("</a>");}
152152

153153
{BrowseableURI} {
154-
appendLink(yytext());
154+
appendLink(yytext(), true);
155155
}
156156

157157
{FNameChar}+ "@" {FNameChar}+ "." {FNameChar}+

src/org/opensolaris/opengrok/analysis/golang/GolangXref.lex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ Number = (0[xX][0-9a-fA-F]+|[0-9]+\.[0-9]+|[0-9][0-9_]*)([eE][+-]?[0-9]+)?
128128
out.write("</a>");
129129
}
130130
{BrowseableURI} {
131-
appendLink(yytext());
131+
appendLink(yytext(), true);
132132
}
133133
{FNameChar}+ "@" {FNameChar}+ "." {FNameChar}+ { writeEMailAddress(yytext()); }
134134
}

0 commit comments

Comments
 (0)