From f25bcc50676c831616eb55aba4eabeb0a6a8987e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9gis=20Hanol?= Date: Fri, 7 Mar 2014 10:44:04 +0100 Subject: [PATCH] couple of bugfixes identified while importing from VB --- app/models/post.rb | 4 ++-- app/models/post_analyzer.rb | 4 ++-- lib/pretty_text.rb | 2 +- lib/topic_creator.rb | 2 +- vendor/assets/javascripts/better_markdown.js | 14 +++++++++----- 5 files changed, 15 insertions(+), 11 deletions(-) diff --git a/app/models/post.rb b/app/models/post.rb index f659684cbb4..20b3d9d7fd8 100644 --- a/app/models/post.rb +++ b/app/models/post.rb @@ -51,9 +51,9 @@ class Post < ActiveRecord::Base scope :public_posts, -> { joins(:topic).where('topics.archetype <> ?', Archetype.private_message) } scope :private_posts, -> { joins(:topic).where('topics.archetype = ?', Archetype.private_message) } scope :with_topic_subtype, ->(subtype) { joins(:topic).where('topics.subtype = ?', subtype) } - + delegate :username, to: :user - + def self.hidden_reasons @hidden_reasons ||= Enum.new(:flag_threshold_reached, :flag_threshold_reached_again, :new_user_spam_threshold_reached) end diff --git a/app/models/post_analyzer.rb b/app/models/post_analyzer.rb index bfce07133ae..77b1b906a5e 100644 --- a/app/models/post_analyzer.rb +++ b/app/models/post_analyzer.rb @@ -75,7 +75,7 @@ class PostAnalyzer begin uri = URI.parse(u) host = uri.host - @linked_hosts[host] ||= 1 + @linked_hosts[host] ||= 1 unless host.nil? rescue URI::InvalidURIError # An invalid URI does not count as a raw link. next @@ -90,10 +90,10 @@ class PostAnalyzer return [] unless @raw.present? return @raw_links if @raw_links.present? - # Don't include @mentions in the link count @raw_links = [] cooked_document.search("a").each do |l| + # Don't include @mentions in the link count next if l.attributes['href'].nil? || link_is_a_mention?(l) url = l.attributes['href'].to_s @raw_links << url diff --git a/lib/pretty_text.rb b/lib/pretty_text.rb index a07fcc5f608..7f9248d26ee 100644 --- a/lib/pretty_text.rb +++ b/lib/pretty_text.rb @@ -192,7 +192,7 @@ module PrettyText else l["rel"] = "nofollow" end - rescue URI::InvalidURIError + rescue URI::InvalidURIError, URI::InvalidComponentError # add a nofollow anyway l["rel"] = "nofollow" end diff --git a/lib/topic_creator.rb b/lib/topic_creator.rb index 62202f4c6a9..7356c8b81f0 100644 --- a/lib/topic_creator.rb +++ b/lib/topic_creator.rb @@ -55,7 +55,7 @@ class TopicCreator category = find_category - @guardian.ensure_can_create!(Topic,category) + @guardian.ensure_can_create!(Topic, category) topic_params[:category_id] = category.id if category.present? diff --git a/vendor/assets/javascripts/better_markdown.js b/vendor/assets/javascripts/better_markdown.js index fc1a9170123..ec7a3ed21a2 100644 --- a/vendor/assets/javascripts/better_markdown.js +++ b/vendor/assets/javascripts/better_markdown.js @@ -437,11 +437,15 @@ }; function escapeHTML( text ) { - return text.replace( /&/g, "&" ) - .replace( //g, ">" ) - .replace( /"/g, """ ) - .replace( /'/g, "'" ); + if (text && text.length > 0) { + return text.replace( /&/g, "&" ) + .replace( //g, ">" ) + .replace( /"/g, """ ) + .replace( /'/g, "'" ); + } else { + return ""; + } } function render_tree( jsonml ) {