Skip to content

Commit a0f5bd4

Browse files
committed
tel URIs: Add tests for missing RFC 3966 support (wrong escaping of separators)
See https://datatracker.ietf.org/doc/html/rfc3966#section-3
1 parent 06b299c commit a0f5bd4

File tree

1 file changed

+32
-1
lines changed

1 file changed

+32
-1
lines changed

src/test/java/org/owasp/html/SanitizersTest.java

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,37 @@ public static final void testExplicitlyAllowedProtocolsAreCaseInsensitive() {
222222
assertEquals(want, s.sanitize(input));
223223
}
224224

225+
// note: currently fails due to escaping in org.owasp.html.HtmlStreamRenderer.writeOpenTag
226+
@Test
227+
public static final void testTelUriRfc3966WithAllowUrlProtocol(){
228+
PolicyFactory s = new HtmlPolicyBuilder()
229+
.allowElements("a")
230+
.allowAttributes("href").onElements("a")
231+
.allowStandardUrlProtocols()
232+
.allowUrlProtocols("tel")
233+
.toFactory();
234+
String input = (
235+
"<a href=\"tel:1234567890\">A local phone number</a>"
236+
+ "<a href=\"tel:1-234-567\">A number with dashes</a>"
237+
+ "<a href=\"tel:1.234.567\">A number with dots</a>"
238+
+ "<a href=\"tel:023 456 78 90\">Spaces need not be escaped but can</a>"
239+
+ "<a href=\"tel:(555)1234\">Brackets need not be escaped but can</a>"
240+
+ "<a href=\"tel:+1234567890\">The leading plus is a separator and MUST NOT be escaped</a>"
241+
+ "<a href=\"tel:tel:890;phone-context=+123-4-567\">The equals is a separator and MUST NOT be escaped but the plus in the parameter is not a separator and MUST be escaped</a>"
242+
);
243+
String want = (
244+
"<a href=\"tel:1234567890\">A local phone number</a>"
245+
+ "<a href=\"tel:1-234-567\">A number with dashes</a>"
246+
+ "<a href=\"tel:1.234.567\">A number with dots</a>"
247+
+ "<a href=\"tel:023%20456%2078%2090\">Spaces need not be escaped but can</a>"
248+
+ "<a href=\"tel:%28555%291234\">Brackets need not be escaped but can</a>"
249+
// fails, see https://datatracker.ietf.org/doc/html/rfc3966#section-3
250+
+ "<a href=\"tel:+1234567890\">The leading plus is a separator and MUST NOT be escaped</a>"
251+
// fails, see https://datatracker.ietf.org/doc/html/rfc3966#section-3
252+
+ "<a href=\"tel:tel:890;phone-context=;&#43;123-4-567\">The equals is a separator and MUST NOT be escaped but the plus in the parameter is not a separator and MUST be escaped</a>");
253+
assertEquals(want, s.sanitize(input));
254+
}
255+
225256
@Test
226257
public static final void testIssue9StylesInTables() {
227258
String input = ""
@@ -500,7 +531,7 @@ public static final void testStyleGlobally() {
500531
String want = "<h1 style=\"color:green\">This is some green text</h1>";
501532
assertEquals(want, policyBuilder.sanitize(input));
502533
}
503-
534+
504535
static int fac(int n) {
505536
int ifac = 1;
506537
for (int i = 1; i <= n; ++i) {

0 commit comments

Comments
 (0)