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:
Khai Do 2016-07-20 14:33:19 -07:00 committed by David Pursehouse
parent 02e9d0bda9
commit c9c5a8c263
3 changed files with 29 additions and 15 deletions

View File

@ -138,7 +138,7 @@ public abstract class SafeHtml
"(?:[(]" + part + "*" + "[)])*" +
part + "*" +
")",
"<a href=\"$1\" target=\"_blank\">$1</a>");
"<a href=\"$1\" target=\"_blank\" rel=\"nofollow\">$1</a>");
}
/**

View File

@ -25,7 +25,8 @@ public class SafeHtml_LinkifyTest {
final SafeHtml n = o.linkify();
assertThat(o).isNotSameAs(n);
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
@ -34,7 +35,8 @@ public class SafeHtml_LinkifyTest {
final SafeHtml n = o.linkify();
assertThat(o).isNotSameAs(n);
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
@ -43,7 +45,8 @@ public class SafeHtml_LinkifyTest {
final SafeHtml n = o.linkify();
assertThat(o).isNotSameAs(n);
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
@ -52,7 +55,8 @@ public class SafeHtml_LinkifyTest {
final SafeHtml n = o.linkify();
assertThat(o).isNotSameAs(n);
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
@ -61,7 +65,8 @@ public class SafeHtml_LinkifyTest {
final SafeHtml n = o.linkify();
assertThat(o).isNotSameAs(n);
assertThat(n.asString()).isEqualTo(
"A &lt;<a href=\"http://go.here/\" target=\"_blank\">http://go.here/</a>&gt; B");
"A &lt;<a href=\"http://go.here/\" target=\"_blank\" rel=\"nofollow\""
+ ">http://go.here/</a>&gt; B");
}
@Test
@ -70,7 +75,8 @@ public class SafeHtml_LinkifyTest {
final SafeHtml n = o.linkify();
assertThat(o).isNotSameAs(n);
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
@ -79,7 +85,8 @@ public class SafeHtml_LinkifyTest {
final SafeHtml n = o.linkify();
assertThat(o).isNotSameAs(n);
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
@ -88,7 +95,8 @@ public class SafeHtml_LinkifyTest {
final SafeHtml n = o.linkify();
assertThat(o).isNotSameAs(n);
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
@ -97,7 +105,8 @@ public class SafeHtml_LinkifyTest {
final SafeHtml n = o.linkify();
assertThat(o).isNotSameAs(n);
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) {

View File

@ -65,7 +65,8 @@ public class SafeHtml_WikifyTest {
final SafeHtml n = o.wikify();
assertThat(o).isNotSameAs(n);
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
@ -74,7 +75,8 @@ public class SafeHtml_WikifyTest {
final SafeHtml n = o.wikify();
assertThat(o).isNotSameAs(n);
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
@ -83,7 +85,8 @@ public class SafeHtml_WikifyTest {
final SafeHtml n = o.wikify();
assertThat(o).isNotSameAs(n);
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
@ -92,7 +95,8 @@ public class SafeHtml_WikifyTest {
final SafeHtml n = o.wikify();
assertThat(o).isNotSameAs(n);
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
@ -101,7 +105,8 @@ public class SafeHtml_WikifyTest {
final SafeHtml n = o.wikify();
assertThat(o).isNotSameAs(n);
assertThat(n.asString()).isEqualTo(
"<p>A &lt;<a href=\"http://go.here/\" target=\"_blank\">http://go.here/</a>&gt; B</p>");
"<p>A &lt;<a href=\"http://go.here/\" target=\"_blank\" rel=\"nofollow\""
+ ">http://go.here/</a>&gt; B</p>");
}
private static SafeHtml html(String text) {