0

Sometimes I get data feed like this: -65° to 180°F. I unescaped this HTML, which will give me -65° to 180°F. whereas what I need is -65° to 180°F. Which brings me to conclusion that I need to unescape the HTML twice.

I've use this simple code to unescapeHTML twice.

String newtext = StringEscapeUtils.unescapeHtml(text);
String newtext2 = StringEscapeUtils.unescapeHtml(newtext);

But when I print the newtext2 contents, it's still shows -65° to 180°F. This still happened even if I unescaped it thrice. Why did the unescapeHTML can't unescape the HTML the second time? How can I work around this?

Chen Li Yong
  • 5,459
  • 8
  • 58
  • 124

2 Answers2

0

if i understood your questioan right you wanted to ° to °

You should use ° or & #xb0; This will convert it into degree. take a look at the link

http://www.fileformat.info/info/unicode/char/b0/index.htm

Kick Buttowski
  • 6,709
  • 13
  • 37
  • 58
  • Yes I want a degree symbol. but the problem is the data is coming from database, and I don't have control over the database. I just have control over the presentation layer (HTML, JSP, CSS) which is just displayed the information through as it is (and adding the necessary unescaping, of course). – Chen Li Yong Dec 12 '13 at 03:03
  • what you mean you do not have any control over the database? how is it possible? – Kick Buttowski Dec 12 '13 at 03:04
  • Even though it's us who built it, the database belongs to department store that has transaction and can be manipulated by anybody who has access to the database. If I have access to the database, I can, for example, make an already paid purchased transaction that send expensive items to my house without spending a single penny. Because of that risk, even the company I work choose not to directly manage the database, so that if there's any case of data manipulation, they can't sue us. We only take care of the database if there's problem happened. Isn't this a common practice, I believe? – Chen Li Yong Dec 13 '13 at 01:37
0

A workaround would be to replace the strings that you know are not escaped correctly, beforehand in an if-class

String not replacing characters

Community
  • 1
  • 1
javanoob
  • 243
  • 1
  • 10
  • 1
    I see. In the past, I've tried to create my own unescape HTML function before I knew the StringEscapeUtils.UnescapeHTML using string.replace, but it didn't work so well. But maybe it will work on this very special occasion. I'll give it a try. Thanks. :) – Chen Li Yong Dec 12 '13 at 03:05