Add rel=nofollow parameter to links in comments
Spamming a Gerrit site is a real issue: https://groups.google.com/d/msg/repo-discuss/Q9x23wnOQXg/aAtXSGqNAwAJ Google recommends adding rel="nofollow"[1] to links on comments: "This can discourage spammers from targeting your site, and will help keep your site from inadvertently passing PageRank to bad neighborhoods on the web". [1] https://support.google.com/webmasters/answer/96569?hl=en Change-Id: I17c2c6f009d31db1c91b39d37227edebf923373a
This commit is contained in:
committed by
David Pursehouse
parent
02e9d0bda9
commit
c9c5a8c263
@@ -138,7 +138,7 @@ public abstract class SafeHtml
|
|||||||
"(?:[(]" + part + "*" + "[)])*" +
|
"(?:[(]" + part + "*" + "[)])*" +
|
||||||
part + "*" +
|
part + "*" +
|
||||||
")",
|
")",
|
||||||
"<a href=\"$1\" target=\"_blank\">$1</a>");
|
"<a href=\"$1\" target=\"_blank\" rel=\"nofollow\">$1</a>");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -25,7 +25,8 @@ public class SafeHtml_LinkifyTest {
|
|||||||
final SafeHtml n = o.linkify();
|
final SafeHtml n = o.linkify();
|
||||||
assertThat(o).isNotSameAs(n);
|
assertThat(o).isNotSameAs(n);
|
||||||
assertThat(n.asString()).isEqualTo(
|
assertThat(n.asString()).isEqualTo(
|
||||||
"A <a href=\"http://go.here/\" target=\"_blank\">http://go.here/</a> B");
|
"A <a href=\"http://go.here/\" target=\"_blank\" rel=\"nofollow\""
|
||||||
|
+ ">http://go.here/</a> B");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -34,7 +35,8 @@ public class SafeHtml_LinkifyTest {
|
|||||||
final SafeHtml n = o.linkify();
|
final SafeHtml n = o.linkify();
|
||||||
assertThat(o).isNotSameAs(n);
|
assertThat(o).isNotSameAs(n);
|
||||||
assertThat(n.asString()).isEqualTo(
|
assertThat(n.asString()).isEqualTo(
|
||||||
"A <a href=\"https://go.here/\" target=\"_blank\">https://go.here/</a> B");
|
"A <a href=\"https://go.here/\" target=\"_blank\" rel=\"nofollow\""
|
||||||
|
+ ">https://go.here/</a> B");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -43,7 +45,8 @@ public class SafeHtml_LinkifyTest {
|
|||||||
final SafeHtml n = o.linkify();
|
final SafeHtml n = o.linkify();
|
||||||
assertThat(o).isNotSameAs(n);
|
assertThat(o).isNotSameAs(n);
|
||||||
assertThat(n.asString()).isEqualTo(
|
assertThat(n.asString()).isEqualTo(
|
||||||
"A (<a href=\"http://go.here/\" target=\"_blank\">http://go.here/</a>) B");
|
"A (<a href=\"http://go.here/\" target=\"_blank\" rel=\"nofollow\""
|
||||||
|
+ ">http://go.here/</a>) B");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -52,7 +55,8 @@ public class SafeHtml_LinkifyTest {
|
|||||||
final SafeHtml n = o.linkify();
|
final SafeHtml n = o.linkify();
|
||||||
assertThat(o).isNotSameAs(n);
|
assertThat(o).isNotSameAs(n);
|
||||||
assertThat(n.asString()).isEqualTo(
|
assertThat(n.asString()).isEqualTo(
|
||||||
"A <a href=\"http://go.here/#m()\" target=\"_blank\">http://go.here/#m()</a> B");
|
"A <a href=\"http://go.here/#m()\" target=\"_blank\" rel=\"nofollow\""
|
||||||
|
+ ">http://go.here/#m()</a> B");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -61,7 +65,8 @@ public class SafeHtml_LinkifyTest {
|
|||||||
final SafeHtml n = o.linkify();
|
final SafeHtml n = o.linkify();
|
||||||
assertThat(o).isNotSameAs(n);
|
assertThat(o).isNotSameAs(n);
|
||||||
assertThat(n.asString()).isEqualTo(
|
assertThat(n.asString()).isEqualTo(
|
||||||
"A <<a href=\"http://go.here/\" target=\"_blank\">http://go.here/</a>> B");
|
"A <<a href=\"http://go.here/\" target=\"_blank\" rel=\"nofollow\""
|
||||||
|
+ ">http://go.here/</a>> B");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -70,7 +75,8 @@ public class SafeHtml_LinkifyTest {
|
|||||||
final SafeHtml n = o.linkify();
|
final SafeHtml n = o.linkify();
|
||||||
assertThat(o).isNotSameAs(n);
|
assertThat(o).isNotSameAs(n);
|
||||||
assertThat(n.asString()).isEqualTo(
|
assertThat(n.asString()).isEqualTo(
|
||||||
"A <a href=\"http://go.here/foo\" target=\"_blank\">http://go.here/foo</a> B");
|
"A <a href=\"http://go.here/foo\" target=\"_blank\" rel=\"nofollow\""
|
||||||
|
+ ">http://go.here/foo</a> B");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -79,7 +85,8 @@ public class SafeHtml_LinkifyTest {
|
|||||||
final SafeHtml n = o.linkify();
|
final SafeHtml n = o.linkify();
|
||||||
assertThat(o).isNotSameAs(n);
|
assertThat(o).isNotSameAs(n);
|
||||||
assertThat(n.asString()).isEqualTo(
|
assertThat(n.asString()).isEqualTo(
|
||||||
"A <a href=\"http://go.here/\" target=\"_blank\">http://go.here/</a>. B");
|
"A <a href=\"http://go.here/\" target=\"_blank\" rel=\"nofollow\""
|
||||||
|
+ ">http://go.here/</a>. B");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -88,7 +95,8 @@ public class SafeHtml_LinkifyTest {
|
|||||||
final SafeHtml n = o.linkify();
|
final SafeHtml n = o.linkify();
|
||||||
assertThat(o).isNotSameAs(n);
|
assertThat(o).isNotSameAs(n);
|
||||||
assertThat(n.asString()).isEqualTo(
|
assertThat(n.asString()).isEqualTo(
|
||||||
"A <a href=\"http://go.here/\" target=\"_blank\">http://go.here/</a>, B");
|
"A <a href=\"http://go.here/\" target=\"_blank\" rel=\"nofollow\""
|
||||||
|
+ ">http://go.here/</a>, B");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -97,7 +105,8 @@ public class SafeHtml_LinkifyTest {
|
|||||||
final SafeHtml n = o.linkify();
|
final SafeHtml n = o.linkify();
|
||||||
assertThat(o).isNotSameAs(n);
|
assertThat(o).isNotSameAs(n);
|
||||||
assertThat(n.asString()).isEqualTo(
|
assertThat(n.asString()).isEqualTo(
|
||||||
"A <a href=\"http://go.here/.\" target=\"_blank\">http://go.here/.</a>. B");
|
"A <a href=\"http://go.here/.\" target=\"_blank\" rel=\"nofollow\""
|
||||||
|
+ ">http://go.here/.</a>. B");
|
||||||
}
|
}
|
||||||
|
|
||||||
private static SafeHtml html(String text) {
|
private static SafeHtml html(String text) {
|
||||||
|
|||||||
@@ -65,7 +65,8 @@ public class SafeHtml_WikifyTest {
|
|||||||
final SafeHtml n = o.wikify();
|
final SafeHtml n = o.wikify();
|
||||||
assertThat(o).isNotSameAs(n);
|
assertThat(o).isNotSameAs(n);
|
||||||
assertThat(n.asString()).isEqualTo(
|
assertThat(n.asString()).isEqualTo(
|
||||||
"<p>A <a href=\"http://go.here/\" target=\"_blank\">http://go.here/</a> B</p>");
|
"<p>A <a href=\"http://go.here/\" target=\"_blank\" rel=\"nofollow\""
|
||||||
|
+ ">http://go.here/</a> B</p>");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -74,7 +75,8 @@ public class SafeHtml_WikifyTest {
|
|||||||
final SafeHtml n = o.wikify();
|
final SafeHtml n = o.wikify();
|
||||||
assertThat(o).isNotSameAs(n);
|
assertThat(o).isNotSameAs(n);
|
||||||
assertThat(n.asString()).isEqualTo(
|
assertThat(n.asString()).isEqualTo(
|
||||||
"<p>A <a href=\"https://go.here/\" target=\"_blank\">https://go.here/</a> B</p>");
|
"<p>A <a href=\"https://go.here/\" target=\"_blank\" rel=\"nofollow\""
|
||||||
|
+ ">https://go.here/</a> B</p>");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -83,7 +85,8 @@ public class SafeHtml_WikifyTest {
|
|||||||
final SafeHtml n = o.wikify();
|
final SafeHtml n = o.wikify();
|
||||||
assertThat(o).isNotSameAs(n);
|
assertThat(o).isNotSameAs(n);
|
||||||
assertThat(n.asString()).isEqualTo(
|
assertThat(n.asString()).isEqualTo(
|
||||||
"<p>A (<a href=\"http://go.here/\" target=\"_blank\">http://go.here/</a>) B</p>");
|
"<p>A (<a href=\"http://go.here/\" target=\"_blank\" rel=\"nofollow\""
|
||||||
|
+ ">http://go.here/</a>) B</p>");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -92,7 +95,8 @@ public class SafeHtml_WikifyTest {
|
|||||||
final SafeHtml n = o.wikify();
|
final SafeHtml n = o.wikify();
|
||||||
assertThat(o).isNotSameAs(n);
|
assertThat(o).isNotSameAs(n);
|
||||||
assertThat(n.asString()).isEqualTo(
|
assertThat(n.asString()).isEqualTo(
|
||||||
"<p>A <a href=\"http://go.here/#m()\" target=\"_blank\">http://go.here/#m()</a> B</p>");
|
"<p>A <a href=\"http://go.here/#m()\" target=\"_blank\" rel=\"nofollow\""
|
||||||
|
+ ">http://go.here/#m()</a> B</p>");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -101,7 +105,8 @@ public class SafeHtml_WikifyTest {
|
|||||||
final SafeHtml n = o.wikify();
|
final SafeHtml n = o.wikify();
|
||||||
assertThat(o).isNotSameAs(n);
|
assertThat(o).isNotSameAs(n);
|
||||||
assertThat(n.asString()).isEqualTo(
|
assertThat(n.asString()).isEqualTo(
|
||||||
"<p>A <<a href=\"http://go.here/\" target=\"_blank\">http://go.here/</a>> B</p>");
|
"<p>A <<a href=\"http://go.here/\" target=\"_blank\" rel=\"nofollow\""
|
||||||
|
+ ">http://go.here/</a>> B</p>");
|
||||||
}
|
}
|
||||||
|
|
||||||
private static SafeHtml html(String text) {
|
private static SafeHtml html(String text) {
|
||||||
|
|||||||
Reference in New Issue
Block a user