Skip to content

Commit

Permalink
Add ${__escapeXml()} function. Contributed by Michael Osipov (michael…
Browse files Browse the repository at this point in the history
…o at apache.org)

This closes #288 on github.

Bugzilla Id: 60883


git-svn-id: https://svn.apache.org/repos/asf/jmeter/trunk@1790429 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
FSchumacher committed Apr 6, 2017
1 parent cebf1ae commit dd5eddd
Show file tree
Hide file tree
Showing 7 changed files with 79 additions and 11 deletions.
6 changes: 6 additions & 0 deletions docs/changes.html
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,12 @@ <h3>Timers, Assertions, Config, Pre- &amp; Post-Processors</h3>

<h3>Functions</h3>
<ul>
<li><a href="https://bz.apache.org/bugzilla/show_bug.cgi?id=60883">
Bug
60883</a>
-
<a href="https://github.com/apache/jmeter/pull/288">
Pull request #288</a> - Add <span class="code">${__escapeXml()}</span> function. Contributed by Michael Osipov (michaelo at apache.org)</li>
</ul>

<h3>I18N</h3>
Expand Down
21 changes: 21 additions & 0 deletions docs/usermanual/functions.html
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@
<tr><td>String</td><td> <a href="#__unescape">unescape</a></td><td>Process strings containing Java escapes (e.g. \n &amp; \t)</td><td>2.3.3</td></tr>
<tr><td>String</td><td> <a href="#__unescapeHtml">unescapeHtml</a></td><td>Decode HTML-encoded strings</td><td>2.3.3</td></tr>
<tr><td>String</td><td> <a href="#__escapeHtml">escapeHtml</a></td><td>Encode strings using HTML encoding</td><td>2.3.3</td></tr>
<tr><td>String</td><td> <a href="#__escapeXml">escapeXml</a></td><td>Encode strings using XMl encoding</td><td>3.2</td></tr>
<tr><td>String</td><td> <a href="#__urldecode">urldecode</a></td><td>Decode a application/x-www-form-urlencoded string</td><td>2.10</td></tr>
<tr><td>String</td><td> <a href="#__urlencode">urlencode</a></td><td>Encode a string to a application/x-www-form-urlencoded string</td><td>2.10</td></tr>
<tr><td>String</td><td> <a href="#__TestPlanName">TestPlanName</a></td><td>Return name of current test plan</td><td>2.6</td></tr>
Expand Down Expand Up @@ -1305,6 +1306,26 @@
</div><div class="required req-false">No</div></div>
</div><div class="go-top"><a href="#">^</a></div></div>

<div class="component"><h2 id="__escapeXml">__escapeXml<a class="sectionlink" href="#__escapeXml" title="Link to here">&para;</a></h2><div class="description">
<p>
Function which escapes the characters in a String using XML 1.0 entities.
</p>
<p>
For example,<span class="code">"bread" &amp; 'butter'</span>
becomes:
<span class="code">&amp;quot;bread&amp;quot; &amp;amp; &amp;apos;butter&amp;apos;</span>.
</p>
<p>
Uses <span class="code">StringEscapeUtils#escapeXml10(String)</span> from Commons Lang.
</p>
</div><div class="properties"><h3 id="__escapeXml_parms1">
Parameters
<a class="sectionlink" href="#__escapeXml_parms1" title="Link to here">&para;</a></h3><div class="property title"><div class="name title">Attribute</div><div class="description title">Description</div><div class="required title">Required</div></div>
<div class="property"><div class="name req-true">String to escape</div><div class="description req-true">
The string to be escaped.
</div><div class="required req-true">Yes</div></div>
</div><div class="go-top"><a href="#">^</a></div></div>

</div>

<div class="subsection"><h2 id="predefinedvars">21.6 Pre-defined Variables<a class="sectionlink" href="#predefinedvars" title="Link to here">&para;</a></h2>
Expand Down
1 change: 1 addition & 0 deletions src/core/org/apache/jmeter/resources/messages.properties
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,7 @@ error_occurred=Error Occurred
error_title=Error
es=Spanish
escape_html_string=String to escape
escape_xml_string=String to escape
eval_name_param=Text containing variable and function references
evalvar_name_param=Name of variable
example_data=Sample Data
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,7 @@ error_occurred=Une erreur est survenue
error_title=Erreur
es=Espagnol
escape_html_string=Cha\u00EEne d'\u00E9chappement
escape_xml_string=Cha\u00EEne d'\u00E9chappement
eval_name_param=Variable contenant du texte et r\u00E9f\u00E9rences de fonctions
evalvar_name_param=Nom de variable
example_data=Exemple de donn\u00E9e
Expand Down
37 changes: 26 additions & 11 deletions test/src/org/apache/jmeter/functions/TestSimpleFunctions.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*
*/

package org.apache.jmeter.functions;
Expand Down Expand Up @@ -59,13 +59,13 @@ public void testUUIDParameterCount() throws Exception {
AbstractFunction function = new Uuid();
checkInvalidParameterCounts(function, 0, 0);
}

@Test
public void testThreadNumberParameterCount() throws Exception {
AbstractFunction function = new ThreadNumber();
checkInvalidParameterCounts(function, 0, 0);
}

@Test
public void testEscapeHtmlParameterCount() throws Exception {
AbstractFunction function = new EscapeHtml();
Expand All @@ -77,36 +77,42 @@ public void testUnEscapeHtmlParameterCount() throws Exception {
AbstractFunction function = new UnEscapeHtml();
checkInvalidParameterCounts(function, 1, 1);
}


@Test
public void testEscapeXmlParameterCount() throws Exception {
AbstractFunction function = new EscapeXml();
checkInvalidParameterCounts(function, 1, 1);
}

@Test
public void testUnEscapeParameterCount() throws Exception {
AbstractFunction function = new UnEscape();
checkInvalidParameterCounts(function, 1, 1);
}

@Test
public void testTestPlanParameterCount() throws Exception {
AbstractFunction function = new TestPlanName();
checkInvalidParameterCounts(function, 0, 0);
}

@Test
public void testThreadNumber() throws Exception {
AbstractFunction function = new ThreadNumber();
function.setParameters(params);
String ret = function.execute(result, null);
assertEquals("1", ret);
}


@Test
public void testUuid() throws Exception {
AbstractFunction function = new Uuid();
function.setParameters(params);
String ret = function.execute(result, null);
UUID.fromString(ret);
}

@Test
public void testEscapeHtml() throws Exception {
AbstractFunction function = new EscapeHtml();
Expand All @@ -115,7 +121,7 @@ public void testEscapeHtml() throws Exception {
String ret = function.execute(result, null);
assertEquals("&quot;bread&quot; &amp; &quot;butter&quot;", ret);
}

@Test
public void testUnEscapeHtml() throws Exception {
AbstractFunction function = new UnEscapeHtml();
Expand All @@ -124,7 +130,16 @@ public void testUnEscapeHtml() throws Exception {
String ret = function.execute(result, null);
assertEquals("\"bread\" & \"butter\"", ret);
}


@Test
public void testEscapeXml() throws Exception {
AbstractFunction function = new EscapeXml();
params.add(new CompoundVariable("\"bread\" & <'butter'>"));
function.setParameters(params);
String ret = function.execute(result, null);
assertEquals("&quot;bread&quot; &amp; &lt;&apos;butter&apos;&gt;", ret);
}

@Test
public void testTestPlanName() throws Exception {
AbstractFunction function = new TestPlanName();
Expand Down
1 change: 1 addition & 0 deletions xdocs/changes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,7 @@ jmeter.reportgenerator.apdex_per_transaction=sample(\\d+):1000|2000;\

<h3>Functions</h3>
<ul>
<li><bug>60883</bug><pr>288</pr> - Add <code>${__escapeXml()}</code> function. Contributed by Michael Osipov (michaelo at apache.org)</li>
</ul>

<h3>I18N</h3>
Expand Down
23 changes: 23 additions & 0 deletions xdocs/usermanual/functions.xml
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ Alternatively, just use <code>/</code> instead for the path separator - e.g. <co
<tr><td>String</td><td> <a href="#__unescape">unescape</a></td><td>Process strings containing Java escapes (e.g. \n &amp; \t)</td><td>2.3.3</td></tr>
<tr><td>String</td><td> <a href="#__unescapeHtml">unescapeHtml</a></td><td>Decode HTML-encoded strings</td><td>2.3.3</td></tr>
<tr><td>String</td><td> <a href="#__escapeHtml">escapeHtml</a></td><td>Encode strings using HTML encoding</td><td>2.3.3</td></tr>
<tr><td>String</td><td> <a href="#__escapeXml">escapeXml</a></td><td>Encode strings using XMl encoding</td><td>3.2</td></tr>
<tr><td>String</td><td> <a href="#__urldecode">urldecode</a></td><td>Decode a application/x-www-form-urlencoded string</td><td>2.10</td></tr>
<tr><td>String</td><td> <a href="#__urlencode">urlencode</a></td><td>Encode a string to a application/x-www-form-urlencoded string</td><td>2.10</td></tr>
<tr><td>String</td><td> <a href="#__TestPlanName">TestPlanName</a></td><td>Return name of current test plan</td><td>2.6</td></tr>
Expand Down Expand Up @@ -1476,6 +1477,28 @@ A reference name - <code>refName</code> - for reusing the value created by this
</properties>
</component>

<component index="&sect-num;.5.33" name="__escapeXml">
<description>
<p>
Function which escapes the characters in a String using XML 1.0 entities.
</p>
<p>
For example,<code>&quot;bread&quot; &amp; &apos;butter&apos;</code>
becomes:
<code>&#38;quot;bread&#38;quot; &#38;amp; &#38;apos;butter&#38;apos;</code>.
</p>
<p>
Uses <code>StringEscapeUtils#escapeXml10(String)</code> from Commons Lang.
</p>
</description>

<properties>
<property name="String to escape" required="Yes">
The string to be escaped.
</property>
</properties>
</component>

</subsection>

<subsection name="&sect-num;.6 Pre-defined Variables" anchor="predefinedvars">
Expand Down

0 comments on commit dd5eddd

Please sign in to comment.