Strip Unicode format characters prior post processing
This commit is contained in:
parent
c03eb0c191
commit
6a5a407e49
4 changed files with 35 additions and 3 deletions
|
|
@ -14,6 +14,10 @@ module Diaspora
|
||||||
processor.instance_exec(&block)
|
processor.instance_exec(&block)
|
||||||
processor.message
|
processor.message
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def normalize message
|
||||||
|
message.delete("\u202a-\u202e\u200b-\u200f")
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
attr_reader :message, :options
|
attr_reader :message, :options
|
||||||
|
|
@ -91,6 +95,10 @@ module Diaspora
|
||||||
def camo_urls
|
def camo_urls
|
||||||
@message = Diaspora::Camo.from_markdown(@message)
|
@message = Diaspora::Camo.from_markdown(@message)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def normalize
|
||||||
|
@message = self.class.normalize(@message)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
DEFAULTS = {mentioned_people: [],
|
DEFAULTS = {mentioned_people: [],
|
||||||
|
|
@ -172,6 +180,7 @@ module Diaspora
|
||||||
# @param [Hash] opts Override global output options, see {#initialize}
|
# @param [Hash] opts Override global output options, see {#initialize}
|
||||||
def plain_text_for_json opts={}
|
def plain_text_for_json opts={}
|
||||||
process(opts) {
|
process(opts) {
|
||||||
|
normalize
|
||||||
camo_urls if AppConfig.privacy.camo.proxy_markdown_images?
|
camo_urls if AppConfig.privacy.camo.proxy_markdown_images?
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
@ -180,6 +189,7 @@ module Diaspora
|
||||||
def html opts={}
|
def html opts={}
|
||||||
process(opts) {
|
process(opts) {
|
||||||
escape
|
escape
|
||||||
|
normalize
|
||||||
render_mentions
|
render_mentions
|
||||||
render_tags
|
render_tags
|
||||||
squish
|
squish
|
||||||
|
|
@ -191,6 +201,7 @@ module Diaspora
|
||||||
def markdownified opts={}
|
def markdownified opts={}
|
||||||
process(opts) {
|
process(opts) {
|
||||||
process_newlines
|
process_newlines
|
||||||
|
normalize
|
||||||
camo_urls if AppConfig.privacy.camo.proxy_markdown_images?
|
camo_urls if AppConfig.privacy.camo.proxy_markdown_images?
|
||||||
markdownify
|
markdownify
|
||||||
render_mentions
|
render_mentions
|
||||||
|
|
|
||||||
|
|
@ -25,7 +25,7 @@ module Diaspora
|
||||||
end
|
end
|
||||||
|
|
||||||
def tag_strings
|
def tag_strings
|
||||||
(send(self.class.field_with_tags) || "")
|
MessageRenderer::Processor.normalize(send(self.class.field_with_tags) || "")
|
||||||
.scan(/(?:^|\s)#([#{ActsAsTaggableOn::Tag.tag_text_regexp}]+|<3)/u)
|
.scan(/(?:^|\s)#([#{ActsAsTaggableOn::Tag.tag_text_regexp}]+|<3)/u)
|
||||||
.map(&:first)
|
.map(&:first)
|
||||||
.uniq(&:downcase)
|
.uniq(&:downcase)
|
||||||
|
|
|
||||||
|
|
@ -50,6 +50,12 @@ describe Diaspora::MessageRenderer do
|
||||||
expect(message(entities).html).to eq entities
|
expect(message(entities).html).to eq entities
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it 'normalizes' do
|
||||||
|
expect(
|
||||||
|
message("\u202a#\u200eUSA\u202c").markdownified
|
||||||
|
).to eq %(<p><a class="tag" href="/tags/USA">#USA</a></p>\n)
|
||||||
|
end
|
||||||
|
|
||||||
context 'with mentions' do
|
context 'with mentions' do
|
||||||
it 'makes hovercard links for mentioned people' do
|
it 'makes hovercard links for mentioned people' do
|
||||||
expect(
|
expect(
|
||||||
|
|
@ -107,8 +113,14 @@ describe Diaspora::MessageRenderer do
|
||||||
|
|
||||||
it 'autolinks standard url links' do
|
it 'autolinks standard url links' do
|
||||||
expect(
|
expect(
|
||||||
message("http://joindiaspora.com/"
|
message("http://joindiaspora.com/").markdownified
|
||||||
).markdownified).to include 'href="http://joindiaspora.com/"'
|
).to include 'href="http://joindiaspora.com/"'
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'normalizes' do
|
||||||
|
expect(
|
||||||
|
message("\u202a#\u200eUSA\u202c").markdownified
|
||||||
|
).to eq %(<p><a class="tag" href="/tags/USA">#USA</a></p>\n)
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'when formatting status messages' do
|
context 'when formatting status messages' do
|
||||||
|
|
@ -184,4 +196,12 @@ describe Diaspora::MessageRenderer do
|
||||||
expect(message(text).urls).to eq ["https://www.antifainfoblatt.de/sites/default/files/public/styles/front_full/public/jockpalfreeman.png?itok=OPjHKpmt", "https://www.antifainfoblatt.de/artikel/%E2%80%9Eschlie%C3%9Flich-waren-es-zu-viele%E2%80%9C"]
|
expect(message(text).urls).to eq ["https://www.antifainfoblatt.de/sites/default/files/public/styles/front_full/public/jockpalfreeman.png?itok=OPjHKpmt", "https://www.antifainfoblatt.de/artikel/%E2%80%9Eschlie%C3%9Flich-waren-es-zu-viele%E2%80%9C"]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe "#plain_text_for_json" do
|
||||||
|
it 'normalizes' do
|
||||||
|
expect(
|
||||||
|
message("\u202a#\u200eUSA\u202c").plain_text_for_json
|
||||||
|
).to eq '#USA'
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -139,6 +139,7 @@ shared_examples_for "it is taggable" do
|
||||||
'#-initialhyphen' => '-initialhyphen',
|
'#-initialhyphen' => '-initialhyphen',
|
||||||
'#-initialhyphen tag' => '-initialhyphen',
|
'#-initialhyphen tag' => '-initialhyphen',
|
||||||
'#-initial-hyphen' => '-initial-hyphen',
|
'#-initial-hyphen' => '-initial-hyphen',
|
||||||
|
"\u202a#\u200eUSA\u202c" => 'USA'
|
||||||
}
|
}
|
||||||
|
|
||||||
expected.each do |text,hashtag|
|
expected.each do |text,hashtag|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue