Mercurial > hg > release > icedtea-web-1.6
changeset 1230:1b191e3c2f91
Removed garbage from htmls' width and height
author | Jiri Vanek <jvanek@redhat.com> |
---|---|
date | Fri, 22 May 2015 13:09:52 +0200 |
parents | 9cfc396945d1 |
children | a094a9b3a0bf |
files | ChangeLog netx/net/sourceforge/jnlp/runtime/html/AppletParser.java tests/netx/unit/net/sourceforge/jnlp/runtime/html/AppletParserTest.java |
diffstat | 3 files changed, 81 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- a/ChangeLog Mon May 04 08:48:43 2015 -0400 +++ b/ChangeLog Fri May 22 13:09:52 2015 +0200 @@ -1,3 +1,11 @@ +2015-05-22 Jiri Vanek <jvanek@redhat.com> + + Removed garbage from htmls' width and height + * netx/net/sourceforge/jnlp/runtime/html/AppletParser.java: new method + (sanitizeSize) which remove all non digit content from string + * tests/netx/unit/net/sourceforge/jnlp/runtime/html/AppletParserTest.java: + new file, test for (sanitizeSize) + 2015-05-04 Jie Kang <jkang@redhat.com> Fix policyeditor file flag to work when used standalone
--- a/netx/net/sourceforge/jnlp/runtime/html/AppletParser.java Mon May 04 08:48:43 2015 -0400 +++ b/netx/net/sourceforge/jnlp/runtime/html/AppletParser.java Fri May 22 13:09:52 2015 +0200 @@ -85,8 +85,9 @@ docBase, getArchives(), getMain(), - new Integer(source.getAttribute("width")), - new Integer(source.getAttribute("height")), + //removing all chars from number - like whitespace, px and so on... + new Integer(sanitizeSize(source.getAttribute("width"))), + new Integer(sanitizeSize(source.getAttribute("height"))), createParams()); } @@ -117,7 +118,13 @@ //push all attributes to map NamedNodeMap atts = source.getAttributes(); for (int i = 0; i < atts.getLength(); i++) { - data.put(atts.item(i).getNodeName(), atts.item(i).getTextContent()); + String name = atts.item(i).getNodeName(); + String value = atts.item(i).getTextContent(); + if (name.trim().equalsIgnoreCase("width") + || name.trim().equalsIgnoreCase("height")) { + value = sanitizeSize(value); + } + data.put(name, value); } return new PluginParameters(data); } @@ -165,4 +172,12 @@ return s; } + static String sanitizeSize(String attribute) { + if (attribute == null) { + return "1"; + } + //remove all nondigits + return attribute.replaceAll("[^0-9]+", ""); + } + }
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/netx/unit/net/sourceforge/jnlp/runtime/html/AppletParserTest.java Fri May 22 13:09:52 2015 +0200 @@ -0,0 +1,55 @@ +/* + Copyright (C) 2013 Red Hat, Inc. + + This file is part of IcedTea. + + IcedTea is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License as published by + the Free Software Foundation, version 2. + + IcedTea is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with IcedTea; see the file COPYING. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + 02110-1301 USA. + + Linking this library statically or dynamically with other modules is + making a combined work based on this library. Thus, the terms and + conditions of the GNU General Public License cover the whole + combination. + + As a special exception, the copyright holders of this library give you + permission to link this library with independent modules to produce an + executable, regardless of the license terms of these independent + modules, and to copy and distribute the resulting executable under + terms of your choice, provided that you also meet, for each linked + independent module, the terms and conditions of the license of that + module. An independent module is a module which is not derived from + or based on this library. If you modify this library, you may extend + this exception to your version of the library, but you are not + obligated to do so. If you do not wish to do so, delete this + exception statement from your version. + */ +package net.sourceforge.jnlp.runtime.html; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import org.junit.Test; + +public class AppletParserTest { + + @Test + public void sanitizeSizeTest() { + assertFalse(AppletParser.sanitizeSize(null) == null); + assertEquals("1", AppletParser.sanitizeSize(null)); + assertEquals("800", AppletParser.sanitizeSize("800")); + assertEquals("10", AppletParser.sanitizeSize("10px")); + assertEquals("1000", AppletParser.sanitizeSize(" 1000 ")); + assertEquals("1000", AppletParser.sanitizeSize(" $1000 ")); + } + +}