ealonso/liferay-portal — pull request #129 by lipusz (2014-02-13 11:31:28+00:00)
Title: [TECHNICAL-SUPPORT | February 17] LPS-44122 & LPS-44123

Hey Eudaldo,

https://issues.liferay.com/browse/LPS-44122 & https://issues.liferay.com/browse/LPS-44123

First, apologize to me for sending this pull directly to you, but Tamás @moltam89 has a pretty high load nowadays, so he would not have had the chance to review it within a reasonable time.

Secondly, about my changes.

##### LPS-44122
Background:
- Methods StringUtil#highlight & HtmlImpl#escape work well individually
- It is possible to search for a term that actually also occurs in an espace sequence, for example: (term) 34 --> (quote) '"' --> & # 34;

To deal with it, we should split the existing logic into a 3-steps method:
1. Highlight the given text using escape-safe tags
2. Escape the result text from 1.
3. Replace the temporary tags with the correct highlight tags

Note: we cannot use "$" sign in the escapeSafeHighlight variables, as "$" is a reserved group symbol in regex, because it would result

"java.lang.IllegalArgumentException: Illegal group reference"

Changes:
I did not want to delete lipusz@6e484f6 & lipusz@1d5c959 from the final version, because this way, every reviewers can see how the issue spreads across 2 portlets in the portal. Therefore, the changes of the 4th commit (lipusz@59a3631) can be understood easily.
Ask me to "fixup" them into one commit if you think that would be better.

I could not find a better place to define "DEFAULT_HIGHLIGHT" constants, so I added them to StringUtil.

Summary class seemed to a good choice to centralize the search-related escape & highlight logic to.

##### LPS-44123
Background:
I've found better to address this issue in a separated ticket, despite its changes depend on LPS-44123.

Changes:
No need to call "setHighlightEnabled(true)" in the JSP files, as the default value of the portal-prop is "true", and, if it is set to "false", the current logic in the "setter" already ensures the property check.

Let me know if you have any concerns.

Regards,
Tibor