Reviewers: ihab.awad,
Description:
Caja normalizes the uri "mailto:a...@b" as "mailto:/a%40b".
This change makes the result "mailto:a%40b".
This change also fixes the error message for invalid uris.
Please review this at http://codereview.appspot.com/88118
Affected files:
M src/com/google/caja/lexer/escaping/UriUtil.java
M src/com/google/caja/plugin/templates/TemplateCompiler.java
M tests/com/google/caja/lexer/escaping/UriUtilTest.java
Index: tests/com/google/caja/lexer/escaping/UriUtilTest.java
===================================================================
--- tests/com/google/caja/lexer/escaping/UriUtilTest.java (revision 3549)
+++ tests/com/google/caja/lexer/escaping/UriUtilTest.java (working copy)
@@ -77,4 +77,8 @@
"S" + enc + "://A" + enc + "/P" + enc + "?Q" + enc + "#F" + enc,
UriUtil.normalizeUri("S\uff61://A\uff61/P\uff61?Q\uff61#F\uff61"));
}
+
+ public void testMailto() throws Exception {
+ assertEquals("mailto:a%40b", UriUtil.normalizeUri("mailto:a...@b"));
+ }
}
Index: src/com/google/caja/lexer/escaping/UriUtil.java
===================================================================
--- src/com/google/caja/lexer/escaping/UriUtil.java (revision 3549)
+++ src/com/google/caja/lexer/escaping/UriUtil.java (working copy)
@@ -87,8 +87,8 @@
String query = m.group(4);
String fragment = m.group(5);
- // Path must start with / if the path is not empty or there is an
authority
- // or scheme.
+ // Path must start with / if the path is not empty and there is an
+ // authority.
// Remove unnecessary .. components in path.
StringBuilder sb = new StringBuilder(uri.length());
@@ -100,8 +100,8 @@
sb.append("//");
normalizeAuthority(authority, sb);
}
- if (path.length() != 0 || sb.length() != 0) {
- normalizePath(path, sb.length() != 0, sb);
+ if (path.length() != 0 || authority != null) {
+ normalizePath(path, authority != null, sb);
}
if (query != null) {
sb.append('?');
Index: src/com/google/caja/plugin/templates/TemplateCompiler.java
===================================================================
--- src/com/google/caja/plugin/templates/TemplateCompiler.java (revision
3549)
+++ src/com/google/caja/plugin/templates/TemplateCompiler.java (working
copy)
@@ -362,8 +362,7 @@
.rewriteUri(ref, info.getMimeTypes());
if (rewrittenUri == null) {
mq.addMessage(
- IhtmlMessageType.MALFORMED_URI,
- FilePosition.UNKNOWN,
+ IhtmlMessageType.MALFORMED_URI, pos,
MessagePart.Factory.valueOf(uri.toString()));
return;
}
@@ -373,7 +372,6 @@
} catch (URISyntaxException ex) {
mq.addMessage(
IhtmlMessageType.MALFORMED_URI, pos,
- FilePosition.UNKNOWN,
MessagePart.Factory.valueOf(value));
return;
}
@@ -506,7 +504,7 @@
* nodes; it is not processed or transformed in any way.
*/
public Pair<Node, List<Block>> getSafeHtml(Document doc) {
- // Inspect the document.
+ // Inspect the document.
inspect();
// Emit safe HTML with JS which attaches dynamic attributes.