sergiogonzalez/liferay-portal — pull request #157 by matethurzo (2012-03-07 17:55:20+00:00)
Title: LPS-15931

Hi Sergio,

This fix affects the national character highlights when you are searching in the portal.

The problem was that initially the portal passed the query terms to the StringUtil.highlight method and it used a regex pattern to highlight the searched terms. It also used the Pattern.quote() method on the string we wanted to match. This method appended a \Q to the beginning to the string and a \E to the end of the string. these two tells the regex engine to treat that text as a string literal so if it would contain a dot character or a question mark it doesn't try to parse that as a regex expression. So if we wanted to highlight the term "app.le" it would turn that to "\Qapp.le\E" and we would highlight the app.le strings in the search results.

We also used the Pattern.CANON_EQ flag for the regex matching witch means that national characters like the Czech character č and cˇ are considered the same.

So the root cause of the problem is when we quoted national characters like that the CANON_EQ treated them differently, because there are some limitations on how that works: http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4867170

So this solution does not use the Pattern.quote method, but instead the Pattern.LITERAL. there is a thread on the stackoverflow if these two are equivalent and it seems they are: http://stackoverflow.com/questions/9263673/why-does-pattern-compile-u00e9-pattern-canon-eq-throw

Please let me know if you have any questions or comments,

thanks,

Máté