Author: pmouawad Date: Mon Jan 14 22:30:00 2019 New Revision: 1851300 URL: http://svn.apache.org/viewvc?rev=1851300&view=rev Log: Bug 63048 - JMeter does not retrieve link resources of type "shortcut icon" or "icon"
Contributed by UbikLoadPack (https://ubikloadpack.com) Bugzilla Id: 63048 Modified: jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/parser/HTMLParser.java jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/parser/JsoupBasedHtmlParser.java jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/parser/LagartoBasedHtmlParser.java jmeter/trunk/test/src/org/apache/jmeter/protocol/http/parser/TestBug60842HtmlParser.java jmeter/trunk/xdocs/changes.xml Modified: jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/parser/HTMLParser.java URL: http://svn.apache.org/viewvc/jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/parser/HTMLParser.java?rev=1851300&r1=1851299&r2=1851300&view=diff ============================================================================== --- jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/parser/HTMLParser.java (original) +++ jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/parser/HTMLParser.java Mon Jan 14 22:30:00 2019 @@ -61,6 +61,9 @@ public abstract class HTMLParser extends protected static final String TAG_SCRIPT = "script";// $NON-NLS-1$ protected static final String STYLESHEET = "stylesheet";// $NON-NLS-1$ + protected static final String SHORTCUT_ICON = "shortcut icon"; + protected static final String ICON = "icon"; + protected static final String IE_UA = "MSIE ([0-9]+.[0-9]+)";// $NON-NLS-1$ protected static final Pattern IE_UA_PATTERN = Pattern.compile(IE_UA); private static final float IE_10 = 10.0f; Modified: jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/parser/JsoupBasedHtmlParser.java URL: http://svn.apache.org/viewvc/jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/parser/JsoupBasedHtmlParser.java?rev=1851300&r1=1851299&r2=1851300&view=diff ============================================================================== --- jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/parser/JsoupBasedHtmlParser.java (original) +++ jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/parser/JsoupBasedHtmlParser.java Mon Jan 14 22:30:00 2019 @@ -89,7 +89,7 @@ public class JsoupBasedHtmlParser extend baseUrl.url = ConversionUtils.makeRelativeURL(baseUrl.url, baseref); } } catch (MalformedURLException e1) { - throw new RuntimeException(e1); + throw new IllegalArgumentException("Error creating relative url from " + baseref, e1); } } else if (tagName.equals(TAG_IMAGE)) { extractAttribute(tag, ATT_SRC); @@ -112,8 +112,10 @@ public class JsoupBasedHtmlParser extend } else if (tagName.equals(TAG_BGSOUND)){ extractAttribute(tag, ATT_SRC); } else if (tagName.equals(TAG_LINK)) { + String relAttr = tag.attr(ATT_REL); // Putting the string first means it works even if the attribute is null - if (STYLESHEET.equalsIgnoreCase(tag.attr(ATT_REL))) { + if (STYLESHEET.equalsIgnoreCase(relAttr) || ICON.equalsIgnoreCase(relAttr) + || SHORTCUT_ICON.equalsIgnoreCase(relAttr)) { extractAttribute(tag, ATT_HREF); } } else { @@ -142,7 +144,7 @@ public class JsoupBasedHtmlParser extend String contents = new String(html,encoding); Document doc = Jsoup.parse(contents); JMeterNodeVisitor nodeVisitor = new JMeterNodeVisitor(new URLPointer(baseUrl), coll); - new NodeTraversor(nodeVisitor).traverse(doc); + NodeTraversor.traverse(nodeVisitor, doc); return coll.iterator(); } catch (Exception e) { throw new HTMLParseException(e); Modified: jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/parser/LagartoBasedHtmlParser.java URL: http://svn.apache.org/viewvc/jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/parser/LagartoBasedHtmlParser.java?rev=1851300&r1=1851299&r2=1851300&view=diff ============================================================================== --- jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/parser/LagartoBasedHtmlParser.java (original) +++ jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/parser/LagartoBasedHtmlParser.java Mon Jan 14 22:30:00 2019 @@ -20,9 +20,10 @@ package org.apache.jmeter.protocol.http. import java.net.MalformedURLException; import java.net.URL; +import java.util.ArrayDeque; import java.util.Collections; +import java.util.Deque; import java.util.Iterator; -import java.util.Stack; import org.apache.commons.lang3.StringUtils; import org.apache.jmeter.protocol.http.util.ConversionUtils; @@ -64,7 +65,7 @@ public class LagartoBasedHtmlParser exte private URLCollection urls; private URLPointer baseUrl; private Float ieVersion; - private Stack<Boolean> enabled = new Stack<>(); + private Deque<Boolean> enabled = new ArrayDeque<>(); /** * @param baseUrl base url to add possibly missing information to urls found in <code>urls</code> @@ -123,7 +124,7 @@ public class LagartoBasedHtmlParser exte baseUrl.url = ConversionUtils.makeRelativeURL(baseUrl.url, baseref.toString()); } } catch (MalformedURLException e1) { - throw new RuntimeException(e1); + throw new IllegalArgumentException("Error creating relative url from " + baseref, e1); } } else if (tag.nameEquals(TAG_IMAGE)) { extractAttribute(tag, ATT_SRC); @@ -151,14 +152,15 @@ public class LagartoBasedHtmlParser exte } else if (tag.nameEquals(TAG_LINK)) { CharSequence relAttribute = tag.getAttributeValue(ATT_REL); // Putting the string first means it works even if the attribute is null - if (relAttribute != null && CharSequenceUtil.equalsIgnoreCase(STYLESHEET,relAttribute)) { + if (relAttribute != null && + (CharSequenceUtil.equalsIgnoreCase(STYLESHEET,relAttribute) + || CharSequenceUtil.equalsIgnoreCase(ICON, relAttribute) + || CharSequenceUtil.equalsIgnoreCase(SHORTCUT_ICON, relAttribute))) { extractAttribute(tag, ATT_HREF); } } else { extractAttribute(tag, ATT_BACKGROUND); } - - // Now look for URLs in the STYLE attribute CharSequence styleTagStr = tag.getAttributeValue(ATT_STYLE); if(!StringUtils.isEmpty(styleTagStr)) { Modified: jmeter/trunk/test/src/org/apache/jmeter/protocol/http/parser/TestBug60842HtmlParser.java URL: http://svn.apache.org/viewvc/jmeter/trunk/test/src/org/apache/jmeter/protocol/http/parser/TestBug60842HtmlParser.java?rev=1851300&r1=1851299&r2=1851300&view=diff ============================================================================== --- jmeter/trunk/test/src/org/apache/jmeter/protocol/http/parser/TestBug60842HtmlParser.java (original) +++ jmeter/trunk/test/src/org/apache/jmeter/protocol/http/parser/TestBug60842HtmlParser.java Mon Jan 14 22:30:00 2019 @@ -107,6 +107,12 @@ public class TestBug60842HtmlParser { new Object[] { parserToTest, "<link href=' with spaces\n.css ' rel='stylesheet'/>", "http://example.org/with spaces.css" }, + new Object[] { parserToTest, + "<link href='favicon.ico' rel='shortcut icon' type='image/vnd.microsoft.icon'/>", + "http://example.org/favicon.ico" }, + new Object[] { parserToTest, + "<link href='favicon.ico' rel='icon' type='image/vnd.microsoft.icon'/>", + "http://example.org/favicon.ico" }, new Object[] { parserToTest, "<embed src=''/>", "" }, new Object[] { parserToTest, "<embed src=' '/>", "" })) { result.add(data); Modified: jmeter/trunk/xdocs/changes.xml URL: http://svn.apache.org/viewvc/jmeter/trunk/xdocs/changes.xml?rev=1851300&r1=1851299&r2=1851300&view=diff ============================================================================== --- jmeter/trunk/xdocs/changes.xml [utf-8] (original) +++ jmeter/trunk/xdocs/changes.xml [utf-8] Mon Jan 14 22:30:00 2019 @@ -180,6 +180,7 @@ of previous time slot as a base. Startin <li><bug>62987</bug>A TestBean element under HTTP(S) Test Script recorder does not work. Contributed by Ubik Load Pack (support at ubikloadpack.com)</li> <li><bug>62987</bug>Abnormal NoHttpResponseException when running request through proxy HTTP(S) Test Script Recorder after a first failing request. Contributed by Ubik Load Pack (support at ubikloadpack.com)</li> <li><bug>62852</bug>HTTP Request Header missing information when using a proxy</li> + <li><bug>63048</bug> - JMeter does not retrieve link resources of type "shortcut icon" or "icon". Contributed by Ubik Load Pack (support at ubikloadpack.com)</li> </ul> <h3>Other Samplers</h3>
