1a58c73ef197c6c18510b6b311dd1aebc38cb2f01Tony Mantler/* 2a58c73ef197c6c18510b6b311dd1aebc38cb2f01Tony Mantler * Copyright (C) 2014 The Android Open Source Project 3a58c73ef197c6c18510b6b311dd1aebc38cb2f01Tony Mantler * 4a58c73ef197c6c18510b6b311dd1aebc38cb2f01Tony Mantler * Licensed under the Apache License, Version 2.0 (the "License"); 5a58c73ef197c6c18510b6b311dd1aebc38cb2f01Tony Mantler * you may not use this file except in compliance with the License. 6a58c73ef197c6c18510b6b311dd1aebc38cb2f01Tony Mantler * You may obtain a copy of the License at 7a58c73ef197c6c18510b6b311dd1aebc38cb2f01Tony Mantler * 8a58c73ef197c6c18510b6b311dd1aebc38cb2f01Tony Mantler * http://www.apache.org/licenses/LICENSE-2.0 9a58c73ef197c6c18510b6b311dd1aebc38cb2f01Tony Mantler * 10a58c73ef197c6c18510b6b311dd1aebc38cb2f01Tony Mantler * Unless required by applicable law or agreed to in writing, software 11a58c73ef197c6c18510b6b311dd1aebc38cb2f01Tony Mantler * distributed under the License is distributed on an "AS IS" BASIS, 12a58c73ef197c6c18510b6b311dd1aebc38cb2f01Tony Mantler * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13a58c73ef197c6c18510b6b311dd1aebc38cb2f01Tony Mantler * See the License for the specific language governing permissions and 14a58c73ef197c6c18510b6b311dd1aebc38cb2f01Tony Mantler * limitations under the License. 15a58c73ef197c6c18510b6b311dd1aebc38cb2f01Tony Mantler */ 16a58c73ef197c6c18510b6b311dd1aebc38cb2f01Tony Mantler 17a58c73ef197c6c18510b6b311dd1aebc38cb2f01Tony Mantlerpackage com.google.android.mail.common.base; 18a58c73ef197c6c18510b6b311dd1aebc38cb2f01Tony Mantler 19a58c73ef197c6c18510b6b311dd1aebc38cb2f01Tony Mantlerimport android.test.suitebuilder.annotation.SmallTest; 20a58c73ef197c6c18510b6b311dd1aebc38cb2f01Tony Mantler 21a58c73ef197c6c18510b6b311dd1aebc38cb2f01Tony Mantlerimport junit.framework.TestCase; 22a58c73ef197c6c18510b6b311dd1aebc38cb2f01Tony Mantler 23a58c73ef197c6c18510b6b311dd1aebc38cb2f01Tony Mantler@SmallTest 24a58c73ef197c6c18510b6b311dd1aebc38cb2f01Tony Mantlerpublic class StringUtilTest extends TestCase { 25a58c73ef197c6c18510b6b311dd1aebc38cb2f01Tony Mantler public void testUnescapeHtml() { 26a58c73ef197c6c18510b6b311dd1aebc38cb2f01Tony Mantler // Unicode Character 'KISSING CAT FACE WITH CLOSED EYES' (U+1F63D) 27a58c73ef197c6c18510b6b311dd1aebc38cb2f01Tony Mantler final String unescaped1 = StringUtil.unescapeHTML("😽"); 28a58c73ef197c6c18510b6b311dd1aebc38cb2f01Tony Mantler assertEquals(unescaped1, "\uD83D\uDE3D"); 29a58c73ef197c6c18510b6b311dd1aebc38cb2f01Tony Mantler 30a58c73ef197c6c18510b6b311dd1aebc38cb2f01Tony Mantler // Unicode Character 'KISSING CAT FACE WITH CLOSED EYES' (U+1F63D) 31a58c73ef197c6c18510b6b311dd1aebc38cb2f01Tony Mantler final String unescaped2 = StringUtil.unescapeHTML("😽"); 32a58c73ef197c6c18510b6b311dd1aebc38cb2f01Tony Mantler assertEquals(unescaped2, "\uD83D\uDE3D"); 33a58c73ef197c6c18510b6b311dd1aebc38cb2f01Tony Mantler 34a58c73ef197c6c18510b6b311dd1aebc38cb2f01Tony Mantler // Unpaired surrogate, should not be converted 35a58c73ef197c6c18510b6b311dd1aebc38cb2f01Tony Mantler final String unescaped3 = StringUtil.unescapeHTML("&#D83D;"); 36a58c73ef197c6c18510b6b311dd1aebc38cb2f01Tony Mantler assertEquals(unescaped3, "&#D83D;"); 37a58c73ef197c6c18510b6b311dd1aebc38cb2f01Tony Mantler 38a58c73ef197c6c18510b6b311dd1aebc38cb2f01Tony Mantler // Paired surrogate, also should not be converted according to HTML spec 39a58c73ef197c6c18510b6b311dd1aebc38cb2f01Tony Mantler final String unescaped4 = StringUtil.unescapeHTML("&#D83D;&#DE3D;"); 40a58c73ef197c6c18510b6b311dd1aebc38cb2f01Tony Mantler assertEquals(unescaped4, "&#D83D;&#DE3D;"); 41a58c73ef197c6c18510b6b311dd1aebc38cb2f01Tony Mantler 42a58c73ef197c6c18510b6b311dd1aebc38cb2f01Tony Mantler // Named entity lowercase 43a58c73ef197c6c18510b6b311dd1aebc38cb2f01Tony Mantler final String unescaped5 = StringUtil.unescapeHTML("α"); 44a58c73ef197c6c18510b6b311dd1aebc38cb2f01Tony Mantler assertEquals(unescaped5, "\u03B1"); 45a58c73ef197c6c18510b6b311dd1aebc38cb2f01Tony Mantler 46a58c73ef197c6c18510b6b311dd1aebc38cb2f01Tony Mantler // Named entity uppercase 47a58c73ef197c6c18510b6b311dd1aebc38cb2f01Tony Mantler final String unescaped6 = StringUtil.unescapeHTML("Α"); 48a58c73ef197c6c18510b6b311dd1aebc38cb2f01Tony Mantler assertEquals(unescaped6, "\u0391"); 49a58c73ef197c6c18510b6b311dd1aebc38cb2f01Tony Mantler } 50a58c73ef197c6c18510b6b311dd1aebc38cb2f01Tony Mantler} 51