Skip to content

Commit dd5eddd

Browse files
committed
Add ${__escapeXml()} function. Contributed by Michael Osipov (michaelo 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
1 parent cebf1ae commit dd5eddd

File tree

7 files changed

+79
-11
lines changed

7 files changed

+79
-11
lines changed

docs/changes.html

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -419,6 +419,12 @@ <h3>Timers, Assertions, Config, Pre- &amp; Post-Processors</h3>
419419

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

424430
<h3>I18N</h3>

docs/usermanual/functions.html

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@
104104
<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>
105105
<tr><td>String</td><td> <a href="#__unescapeHtml">unescapeHtml</a></td><td>Decode HTML-encoded strings</td><td>2.3.3</td></tr>
106106
<tr><td>String</td><td> <a href="#__escapeHtml">escapeHtml</a></td><td>Encode strings using HTML encoding</td><td>2.3.3</td></tr>
107+
<tr><td>String</td><td> <a href="#__escapeXml">escapeXml</a></td><td>Encode strings using XMl encoding</td><td>3.2</td></tr>
107108
<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>
108109
<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>
109110
<tr><td>String</td><td> <a href="#__TestPlanName">TestPlanName</a></td><td>Return name of current test plan</td><td>2.6</td></tr>
@@ -1305,6 +1306,26 @@
13051306
</div><div class="required req-false">No</div></div>
13061307
</div><div class="go-top"><a href="#">^</a></div></div>
13071308

1309+
<div class="component"><h2 id="__escapeXml">__escapeXml<a class="sectionlink" href="#__escapeXml" title="Link to here">&para;</a></h2><div class="description">
1310+
<p>
1311+
Function which escapes the characters in a String using XML 1.0 entities.
1312+
</p>
1313+
<p>
1314+
For example,<span class="code">"bread" &amp; 'butter'</span>
1315+
becomes:
1316+
<span class="code">&amp;quot;bread&amp;quot; &amp;amp; &amp;apos;butter&amp;apos;</span>.
1317+
</p>
1318+
<p>
1319+
Uses <span class="code">StringEscapeUtils#escapeXml10(String)</span> from Commons Lang.
1320+
</p>
1321+
</div><div class="properties"><h3 id="__escapeXml_parms1">
1322+
Parameters
1323+
<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>
1324+
<div class="property"><div class="name req-true">String to escape</div><div class="description req-true">
1325+
The string to be escaped.
1326+
</div><div class="required req-true">Yes</div></div>
1327+
</div><div class="go-top"><a href="#">^</a></div></div>
1328+
13081329
</div>
13091330

13101331
<div class="subsection"><h2 id="predefinedvars">21.6 Pre-defined Variables<a class="sectionlink" href="#predefinedvars" title="Link to here">&para;</a></h2>

src/core/org/apache/jmeter/resources/messages.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,7 @@ error_occurred=Error Occurred
298298
error_title=Error
299299
es=Spanish
300300
escape_html_string=String to escape
301+
escape_xml_string=String to escape
301302
eval_name_param=Text containing variable and function references
302303
evalvar_name_param=Name of variable
303304
example_data=Sample Data

src/core/org/apache/jmeter/resources/messages_fr.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,7 @@ error_occurred=Une erreur est survenue
293293
error_title=Erreur
294294
es=Espagnol
295295
escape_html_string=Cha\u00EEne d'\u00E9chappement
296+
escape_xml_string=Cha\u00EEne d'\u00E9chappement
296297
eval_name_param=Variable contenant du texte et r\u00E9f\u00E9rences de fonctions
297298
evalvar_name_param=Nom de variable
298299
example_data=Exemple de donn\u00E9e

test/src/org/apache/jmeter/functions/TestSimpleFunctions.java

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1414
* See the License for the specific language governing permissions and
1515
* limitations under the License.
16-
*
16+
*
1717
*/
1818

1919
package org.apache.jmeter.functions;
@@ -59,13 +59,13 @@ public void testUUIDParameterCount() throws Exception {
5959
AbstractFunction function = new Uuid();
6060
checkInvalidParameterCounts(function, 0, 0);
6161
}
62-
62+
6363
@Test
6464
public void testThreadNumberParameterCount() throws Exception {
6565
AbstractFunction function = new ThreadNumber();
6666
checkInvalidParameterCounts(function, 0, 0);
6767
}
68-
68+
6969
@Test
7070
public void testEscapeHtmlParameterCount() throws Exception {
7171
AbstractFunction function = new EscapeHtml();
@@ -77,36 +77,42 @@ public void testUnEscapeHtmlParameterCount() throws Exception {
7777
AbstractFunction function = new UnEscapeHtml();
7878
checkInvalidParameterCounts(function, 1, 1);
7979
}
80-
80+
81+
@Test
82+
public void testEscapeXmlParameterCount() throws Exception {
83+
AbstractFunction function = new EscapeXml();
84+
checkInvalidParameterCounts(function, 1, 1);
85+
}
86+
8187
@Test
8288
public void testUnEscapeParameterCount() throws Exception {
8389
AbstractFunction function = new UnEscape();
8490
checkInvalidParameterCounts(function, 1, 1);
8591
}
86-
92+
8793
@Test
8894
public void testTestPlanParameterCount() throws Exception {
8995
AbstractFunction function = new TestPlanName();
9096
checkInvalidParameterCounts(function, 0, 0);
9197
}
92-
98+
9399
@Test
94100
public void testThreadNumber() throws Exception {
95101
AbstractFunction function = new ThreadNumber();
96102
function.setParameters(params);
97103
String ret = function.execute(result, null);
98104
assertEquals("1", ret);
99105
}
100-
101-
106+
107+
102108
@Test
103109
public void testUuid() throws Exception {
104110
AbstractFunction function = new Uuid();
105111
function.setParameters(params);
106112
String ret = function.execute(result, null);
107113
UUID.fromString(ret);
108114
}
109-
115+
110116
@Test
111117
public void testEscapeHtml() throws Exception {
112118
AbstractFunction function = new EscapeHtml();
@@ -115,7 +121,7 @@ public void testEscapeHtml() throws Exception {
115121
String ret = function.execute(result, null);
116122
assertEquals("&quot;bread&quot; &amp; &quot;butter&quot;", ret);
117123
}
118-
124+
119125
@Test
120126
public void testUnEscapeHtml() throws Exception {
121127
AbstractFunction function = new UnEscapeHtml();
@@ -124,7 +130,16 @@ public void testUnEscapeHtml() throws Exception {
124130
String ret = function.execute(result, null);
125131
assertEquals("\"bread\" & \"butter\"", ret);
126132
}
127-
133+
134+
@Test
135+
public void testEscapeXml() throws Exception {
136+
AbstractFunction function = new EscapeXml();
137+
params.add(new CompoundVariable("\"bread\" & <'butter'>"));
138+
function.setParameters(params);
139+
String ret = function.execute(result, null);
140+
assertEquals("&quot;bread&quot; &amp; &lt;&apos;butter&apos;&gt;", ret);
141+
}
142+
128143
@Test
129144
public void testTestPlanName() throws Exception {
130145
AbstractFunction function = new TestPlanName();

xdocs/changes.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,7 @@ jmeter.reportgenerator.apdex_per_transaction=sample(\\d+):1000|2000;\
306306

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

311312
<h3>I18N</h3>

xdocs/usermanual/functions.xml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ Alternatively, just use <code>/</code> instead for the path separator - e.g. <co
143143
<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>
144144
<tr><td>String</td><td> <a href="#__unescapeHtml">unescapeHtml</a></td><td>Decode HTML-encoded strings</td><td>2.3.3</td></tr>
145145
<tr><td>String</td><td> <a href="#__escapeHtml">escapeHtml</a></td><td>Encode strings using HTML encoding</td><td>2.3.3</td></tr>
146+
<tr><td>String</td><td> <a href="#__escapeXml">escapeXml</a></td><td>Encode strings using XMl encoding</td><td>3.2</td></tr>
146147
<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>
147148
<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>
148149
<tr><td>String</td><td> <a href="#__TestPlanName">TestPlanName</a></td><td>Return name of current test plan</td><td>2.6</td></tr>
@@ -1476,6 +1477,28 @@ A reference name - <code>refName</code> - for reusing the value created by this
14761477
</properties>
14771478
</component>
14781479

1480+
<component index="&sect-num;.5.33" name="__escapeXml">
1481+
<description>
1482+
<p>
1483+
Function which escapes the characters in a String using XML 1.0 entities.
1484+
</p>
1485+
<p>
1486+
For example,<code>&quot;bread&quot; &amp; &apos;butter&apos;</code>
1487+
becomes:
1488+
<code>&#38;quot;bread&#38;quot; &#38;amp; &#38;apos;butter&#38;apos;</code>.
1489+
</p>
1490+
<p>
1491+
Uses <code>StringEscapeUtils#escapeXml10(String)</code> from Commons Lang.
1492+
</p>
1493+
</description>
1494+
1495+
<properties>
1496+
<property name="String to escape" required="Yes">
1497+
The string to be escaped.
1498+
</property>
1499+
</properties>
1500+
</component>
1501+
14791502
</subsection>
14801503

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

0 commit comments

Comments
 (0)