mirror of
https://github.com/discourse/discourse.git
synced 2025-02-09 12:54:56 +00:00
parent
674c861eaf
commit
6c4ae05454
@ -1,5 +1,3 @@
|
|||||||
require 'iconv'
|
|
||||||
|
|
||||||
#
|
#
|
||||||
# Given a string, tell us whether or not is acceptable. Also, remove stuff we don't like
|
# Given a string, tell us whether or not is acceptable. Also, remove stuff we don't like
|
||||||
# such as leading / trailing space.
|
# such as leading / trailing space.
|
||||||
@ -13,13 +11,10 @@ class TextSentinel
|
|||||||
end
|
end
|
||||||
|
|
||||||
def initialize(text, opts=nil)
|
def initialize(text, opts=nil)
|
||||||
if text.present?
|
|
||||||
@text = Iconv.new('UTF-8//IGNORE', 'UTF-8').iconv(text.dup)
|
|
||||||
end
|
|
||||||
|
|
||||||
@opts = opts || {}
|
@opts = opts || {}
|
||||||
|
|
||||||
if @text.present?
|
if text.present?
|
||||||
|
@text = text.encode('UTF-8', invalid: :replace, undef: :replace, replace: '')
|
||||||
@text.strip!
|
@text.strip!
|
||||||
@text.gsub!(/ +/m, ' ') if @opts[:remove_interior_spaces]
|
@text.gsub!(/ +/m, ' ') if @opts[:remove_interior_spaces]
|
||||||
end
|
end
|
||||||
|
@ -2,7 +2,6 @@
|
|||||||
|
|
||||||
require 'spec_helper'
|
require 'spec_helper'
|
||||||
require 'text_sentinel'
|
require 'text_sentinel'
|
||||||
require 'iconv'
|
|
||||||
|
|
||||||
describe TextSentinel do
|
describe TextSentinel do
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user