Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/bom-thirdparty/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -129,10 +129,10 @@ dependencies {
api("org.jetbrains.lets-plot:lets-plot-batik:4.1.0")
api("org.jetbrains.lets-plot:lets-plot-kotlin-jvm:4.5.0")
api("org.jetbrains:annotations:24.1.0")
api("org.jodd:jodd-core:5.0.13")
api("org.jodd:jodd-lagarto:5.0.13")
api("org.jodd:jodd-log:5.0.13")
api("org.jodd:jodd-props:5.0.13")
api("org.jodd:jodd-core:5.3.0")
api("org.jodd:jodd-lagarto:6.0.6")
api("org.jodd:jodd-log:5.1.6")
api("org.jodd:jodd-props:6.0.2")
api("org.jsoup:jsoup:1.17.1")
api("org.mongodb:mongo-java-driver:2.14.3")
api("org.mozilla:rhino:1.7.14")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@

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 org.apache.jmeter.protocol.http.util.ConversionUtils;
Expand All @@ -34,7 +32,6 @@
import jodd.lagarto.Tag;
import jodd.lagarto.TagType;
import jodd.lagarto.dom.HtmlCCommentExpressionMatcher;
import jodd.lagarto.dom.LagartoDomBuilderConfig;
import jodd.log.LoggerFactory;
import jodd.log.impl.Slf4jLogger;
import jodd.util.CharSequenceUtil;
Expand All @@ -60,21 +57,16 @@ private URLPointer(URL newUrl) {
}

private static final class JMeterTagVisitor extends EmptyTagVisitor {
private HtmlCCommentExpressionMatcher htmlCCommentExpressionMatcher;
private final URLCollection urls;
private final URLPointer baseUrl;
private final Float ieVersion;
private final Deque<Boolean> enabled = new ArrayDeque<>();

/**
* @param baseUrl base url to add possibly missing information to urls found in <code>urls</code>
* @param urls collection of urls to consider
* @param ieVersion version number of IE to emulate
*/
public JMeterTagVisitor(final URLPointer baseUrl, URLCollection urls, Float ieVersion) {
public JMeterTagVisitor(final URLPointer baseUrl, URLCollection urls) {
this.urls = urls;
this.baseUrl = baseUrl;
this.ieVersion = ieVersion;
}

private void extractAttribute(Tag tag, String attributeName) {
Expand All @@ -93,9 +85,6 @@ private void extractAttribute(Tag tag, String attributeName) {
*/
@Override
public void script(Tag tag, CharSequence body) {
if (!enabled.peek()) {
return;
}
extractAttribute(tag, ATT_SRC);
}

Expand All @@ -106,9 +95,6 @@ public void script(Tag tag, CharSequence body) {
*/
@Override
public void tag(Tag tag) {
if (!enabled.peek()) {
return;
}
TagType tagType = tag.getType();
switch (tagType) {
case START:
Expand Down Expand Up @@ -184,54 +170,16 @@ public void tag(Tag tag) {
break;
}
}

/* (non-Javadoc)
* @see jodd.lagarto.EmptyTagVisitor#condComment(java.lang.CharSequence, boolean, boolean, boolean)
*/
@Override
public void condComment(CharSequence expression, boolean isStartingTag,
boolean isHidden, boolean isHiddenEndTag) {
// See http://css-tricks.com/how-to-create-an-ie-only-stylesheet/
if(!isStartingTag) {
enabled.pop();
} else {
if (htmlCCommentExpressionMatcher == null) {
htmlCCommentExpressionMatcher = new HtmlCCommentExpressionMatcher();
}
String expressionString = expression.toString().trim();
enabled.push(htmlCCommentExpressionMatcher.match(ieVersion,
expressionString));
}
}

/* (non-Javadoc)
* @see jodd.lagarto.EmptyTagVisitor#start()
*/
@Override
public void start() {
super.start();
enabled.clear();
enabled.push(Boolean.TRUE);
}
}

@Override
public Iterator<URL> getEmbeddedResourceURLs(String userAgent, byte[] html, URL baseUrl,
URLCollection coll, String encoding) throws HTMLParseException {
try {
Float ieVersion = extractIEVersion(userAgent);

String contents = new String(html,encoding);
LagartoParser lagartoParser = new LagartoParser(contents.toCharArray());
LagartoDomBuilderConfig config = new LagartoDomBuilderConfig();
config.setCaseSensitive(false);
// Conditional comments only apply for IE < 10
config.setEnableConditionalComments(isEnableConditionalComments(ieVersion));
if(ieVersion != null) {
config.setCondCommentIEVersion(ieVersion);
}
lagartoParser.setConfig(config);
JMeterTagVisitor tagVisitor = new JMeterTagVisitor(new URLPointer(baseUrl), coll, ieVersion);
lagartoParser.getConfig().setCaseSensitive(false);
JMeterTagVisitor tagVisitor = new JMeterTagVisitor(new URLPointer(baseUrl), coll);
lagartoParser.parse(tagVisitor);
return coll.iterator();
} catch (LagartoException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;
Expand Down Expand Up @@ -61,12 +62,6 @@ public class TestHTMLParser extends JMeterTestCase {

private static final String DEFAULT_UA = "Apache-HttpClient/4.2.6";
private static final String UA_FF = "Mozilla/5.0 (Windows NT 5.1; rv:31.0) Gecko/20100101 Firefox/31.0";
private static final String UA_IE55 = "Mozilla/4.0 (compatible;MSIE 5.5; Windows 98)";
private static final String UA_IE6 = "Mozilla/5.0 (Windows; U; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 2.0.50727)";
private static final String UA_IE7 = "Mozilla/5.0 (Windows; U; MSIE 7.0; Windows NT 6.0; en-US)";
private static final String UA_IE8 = "Mozilla/5.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0; "
+ "GTB7.4; InfoPath.2; SV1; .NET CLR 3.3.69573; WOW64; en-US)";
private static final String UA_IE9 = "Mozilla/5.0 (Windows; U; MSIE 9.0; WIndows NT 9.0; en-US))";
private static final String UA_IE10 = "Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; Trident/6.0)";

private static class StaticTestClass // Can't instantiate
Expand Down Expand Up @@ -119,6 +114,10 @@ private TestData(String htmlFileName, String baseUrl, String expectedSet, String
this.userAgent = userAgent;
}

@Override
public String toString() {
return "TestData [userAgent=" + userAgent + ", htmlFileName=" + fileName + ", expectedList=" + expectedList + "]";
}
}

private static final String DEFAULT_JMETER_PARSER =
Expand Down Expand Up @@ -183,26 +182,6 @@ static String[] getParsers() {
null,
"testfiles/HTMLParserTestCaseWithConditional1_FF.all",
UA_FF),
new TestData("testfiles/HTMLParserTestCaseWithConditional1.html",
"http://localhost/mydir/myfile.html",
null,
"testfiles/HTMLParserTestCaseWithConditional1_IE6.all",
UA_IE6),
new TestData("testfiles/HTMLParserTestCaseWithConditional1.html",
"http://localhost/mydir/myfile.html",
null,
"testfiles/HTMLParserTestCaseWithConditional1_IE7.all",
UA_IE7),
new TestData("testfiles/HTMLParserTestCaseWithConditional1.html",
"http://localhost/mydir/myfile.html",
null,
"testfiles/HTMLParserTestCaseWithConditional1_IE8.all",
UA_IE8),
new TestData("testfiles/HTMLParserTestCaseWithConditional1.html",
"http://localhost/mydir/myfile.html",
null,
"testfiles/HTMLParserTestCaseWithConditional1_IE8.all",
UA_IE8),

// FF gets mixed up by nested comments
new TestData("testfiles/HTMLParserTestCaseWithConditional2.html",
Expand All @@ -211,41 +190,17 @@ static String[] getParsers() {
"testfiles/HTMLParserTestCaseWithConditional2_FF.all",
UA_FF),

new TestData("testfiles/HTMLParserTestCaseWithConditional2.html",
"http://localhost/mydir/myfile.html",
null,
"testfiles/HTMLParserTestCaseWithConditional2_IE7.all",
UA_IE7),
new TestData("testfiles/HTMLParserTestCaseWithConditional2.html",
"http://localhost/mydir/myfile.html",
null,
"testfiles/HTMLParserTestCaseWithConditional2_IE8.all",
UA_IE8),
new TestData("testfiles/HTMLParserTestCaseWithConditional2.html",
"http://localhost/mydir/myfile.html",
null,
"testfiles/HTMLParserTestCaseWithConditional2_IE9.all",
UA_IE9),
new TestData("testfiles/HTMLParserTestCaseWithConditional3.html",
"http://localhost/mydir/myfile.html",
null,
"testfiles/HTMLParserTestCaseWithConditional3_FF.all",
UA_FF),

new TestData("testfiles/HTMLParserTestCaseWithConditional3.html",
"http://localhost/mydir/myfile.html",
null,
"testfiles/HTMLParserTestCaseWithConditional3_IE10.all",
UA_IE10),
new TestData("testfiles/HTMLParserTestCaseWithConditional3.html",
"http://localhost/mydir/myfile.html",
null,
"testfiles/HTMLParserTestCaseWithConditional3_IE55.all",
UA_IE55),
new TestData("testfiles/HTMLParserTestCaseWithConditional3.html",
"http://localhost/mydir/myfile.html",
null,
"testfiles/HTMLParserTestCaseWithConditional3_IE6.all",
UA_IE6)
};

static Stream<Arguments> parsersAndTestNumbers() {
Expand All @@ -255,8 +210,8 @@ static Stream<Arguments> parsersAndTestNumbers() {
}

static Stream<Arguments> specificParserTests() {
return IntStream.range(0, SPECIFIC_PARSER_TESTS.length)
.mapToObj(testNumber -> arguments(DEFAULT_JMETER_PARSER, testNumber));
return Arrays.stream(SPECIFIC_PARSER_TESTS)
.map(testData -> arguments(DEFAULT_JMETER_PARSER, testData));
}

// Test if can instantiate parser using property name
Expand Down Expand Up @@ -354,13 +309,13 @@ public void testParserList(String parserName, int testNumber) throws Exception {

@ParameterizedTest
@MethodSource("specificParserTests")
public void testSpecificParserList(String parserName, int testNumber) throws Exception {
public void testSpecificParserList(String parserName, TestData testData) throws Exception {
HTMLParser p = (HTMLParser) BaseParser.getParser(parserName);
filetest(p, SPECIFIC_PARSER_TESTS[testNumber].fileName,
SPECIFIC_PARSER_TESTS[testNumber].baseUrl,
SPECIFIC_PARSER_TESTS[testNumber].expectedList,
filetest(p, testData.fileName,
testData.baseUrl,
testData.expectedList,
new ArrayList<>(), true,
SPECIFIC_PARSER_TESTS[testNumber].userAgent);
testData.userAgent);
}


Expand Down
5 changes: 5 additions & 0 deletions xdocs/changes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,11 @@ Summary
<li><issue>6357</issue><pr>6358</pr> Ensure writable directories when copying template files while report generation.</li>
</ul>

<h3>HTTP Samplers and Test Script Recorder</h3>
<ul>
<li><pr>5891</pr>Skip Internet Explorer 6-9 conditional comment processing when fetching resource links</li>
</ul>

<!-- =================== Thanks =================== -->

<ch_section>Thanks</ch_section>
Expand Down
Loading