mirror of
https://github.com/discourse/discourse.git
synced 2024-11-28 19:53:53 -06:00
FIX: Strip links from google indexed bios when the users are new.
This commit is contained in:
parent
729e4080a6
commit
dfba2b6e0a
@ -433,13 +433,12 @@ class User < ActiveRecord::Base
|
||||
def bio_excerpt
|
||||
excerpt = PrettyText.excerpt(bio_cooked, 350)
|
||||
return excerpt if excerpt.blank? || has_trust_level?(:basic)
|
||||
|
||||
# If the user is not basic, strip links from their bio
|
||||
fragment = Nokogiri::HTML.fragment(excerpt)
|
||||
fragment.css('a').each do |a|
|
||||
a.replace(a.text)
|
||||
PrettyText.strip_links(excerpt)
|
||||
end
|
||||
fragment.to_html
|
||||
|
||||
def bio_processed
|
||||
return bio_cooked if bio_cooked.blank? || has_trust_level?(:basic)
|
||||
PrettyText.strip_links(bio_cooked)
|
||||
end
|
||||
|
||||
def delete_all_posts!(guardian)
|
||||
|
@ -1,6 +1,6 @@
|
||||
<h2><%= @user.username %></h2>
|
||||
|
||||
<p><%= raw @user.bio_cooked %></p>
|
||||
<p><%= raw @user.bio_processed %></p>
|
||||
|
||||
<p><%= t 'powered_by_html' %></p>
|
||||
|
||||
|
@ -239,6 +239,15 @@ module PrettyText
|
||||
ExcerptParser.get_excerpt(html, max_length, options)
|
||||
end
|
||||
|
||||
def self.strip_links(string)
|
||||
return string if string.blank?
|
||||
|
||||
# If the user is not basic, strip links from their bio
|
||||
fragment = Nokogiri::HTML.fragment(string)
|
||||
fragment.css('a').each {|a| a.replace(a.text) }
|
||||
fragment.to_html
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
def self.ctx_load(*files)
|
||||
|
@ -183,6 +183,19 @@ test
|
||||
|
||||
end
|
||||
|
||||
describe "strip links" do
|
||||
it "returns blank for blank input" do
|
||||
expect(PrettyText.strip_links("")).to be_blank
|
||||
end
|
||||
|
||||
it "does nothing to a string without links" do
|
||||
expect(PrettyText.strip_links("I'm the <b>batman</b>")).to eq("I'm the <b>batman</b>")
|
||||
end
|
||||
|
||||
it "strips links but leaves the text content" do
|
||||
expect(PrettyText.strip_links("I'm the linked <a href='http://en.wikipedia.org/wiki/Batman'>batman</a>")).to eq("I'm the linked batman")
|
||||
end
|
||||
end
|
||||
|
||||
describe "apply cdn" do
|
||||
it "should detect bare links to images and apply a CDN" do
|
||||
|
@ -836,7 +836,7 @@ describe User do
|
||||
|
||||
end
|
||||
|
||||
describe "bio_excerpt" do
|
||||
describe "bio link stripping" do
|
||||
|
||||
it "returns an empty string with no bio" do
|
||||
expect(Fabricate.build(:user).bio_excerpt).to be_blank
|
||||
@ -852,11 +852,13 @@ describe User do
|
||||
|
||||
it "includes the link if the user is not new" do
|
||||
expect(user.bio_excerpt).to eq("im sissy and i love <a href='http://ponycorns.com' rel='nofollow'>http://ponycorns.com</a>")
|
||||
expect(user.bio_processed).to eq("<p>im sissy and i love <a href=\"http://ponycorns.com\" rel=\"nofollow\">http://ponycorns.com</a></p>")
|
||||
end
|
||||
|
||||
it "removes the link if the user is new" do
|
||||
user.trust_level = TrustLevel.levels[:newuser]
|
||||
expect(user.bio_excerpt).to eq("im sissy and i love http://ponycorns.com")
|
||||
expect(user.bio_processed).to eq("<p>im sissy and i love http://ponycorns.com</p>")
|
||||
end
|
||||
end
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user