1818 */
1919
2020/*
21- * Copyright (c) 2005, 2014 , Oracle and/or its affiliates. All rights reserved.
21+ * Copyright (c) 2005, 2017 , Oracle and/or its affiliates. All rights reserved.
2222 */
2323
2424package org .opensolaris .opengrok .search .context ;
4343import org .opensolaris .opengrok .search .Hit ;
4444import org .opensolaris .opengrok .search .QueryBuilder ;
4545import org .opensolaris .opengrok .web .Prefix ;
46+ import org .opensolaris .opengrok .web .Util ;
4647
4748/**
4849 * it is supposed to get the matching lines from history log files.
49- * since lucene does not easily give the match context.
50+ * since Lucene does not easily give the match context.
5051 */
5152public class HistoryContext {
5253
@@ -199,21 +200,28 @@ private boolean getHistoryContext(
199200 * @param end position of the first char after the match
200201 * @param flatten should multi-line log entries be flattened to a single
201202 * @param path path to the file
202- * @param wcontext web context (begin of url )
203+ * @param wcontext web context (begin of URL )
203204 * @param nrev old revision
204205 * @param rev current revision
205206 * line? If {@code true}, replace newline with space.
206207 */
207- private void writeMatch (Appendable out , String line ,
208- int start , int end , boolean flatten , String path , String wcontext , String nrev , String rev )
208+ protected static void writeMatch (Appendable out , String line ,
209+ int start , int end , boolean flatten , String path ,
210+ String wcontext , String nrev , String rev )
209211 throws IOException {
212+
210213 String prefix = line .substring (0 , start );
211214 String match = line .substring (start , end );
212215 String suffix = line .substring (end );
213216
214- if (wcontext !=null && nrev !=null && !wcontext .isEmpty () ) {
215- //does below need to be encoded? see bug 16985
216- out .append ("<a href=" +wcontext +Prefix .DIFF_P +path +"?r2=" +path +"@" +rev +"&r1=" +path +"@" +nrev +" title=\" diff to previous version\" >diff</a> " );
217+ if (wcontext != null && nrev != null && !wcontext .isEmpty ()) {
218+ out .append ("<a href=\" " );
219+ printHTML (out , wcontext + Prefix .DIFF_P +
220+ Util .URIEncodePath (path ) +
221+ "?r2=" + Util .URIEncodePath (path ) + "@" + rev +
222+ "&r1=" + Util .URIEncodePath (path ) + "@" + nrev +
223+ "\" title=\" diff to previous version\" " , flatten );
224+ out .append (">diff</a> " );
217225 }
218226
219227 printHTML (out , prefix , flatten );
@@ -231,7 +239,7 @@ private void writeMatch(Appendable out, String line,
231239 * @param flatten should multi-line strings be flattened to a single
232240 * line? If {@code true}, replace newline with space.
233241 */
234- private void printHTML (Appendable out , String str , boolean flatten )
242+ private static void printHTML (Appendable out , String str , boolean flatten )
235243 throws IOException {
236244 for (int i = 0 ; i < str .length (); i ++) {
237245 char ch = str .charAt (i );
0 commit comments