mirror of
https://github.com/discourse/discourse.git
synced 2025-01-31 02:09:28 +08:00
work around bust encodings passed in to method
This commit is contained in:
parent
3bdd2eeeba
commit
415d4df648
|
@ -26,6 +26,13 @@ module ApplicationHelper
|
||||||
def escape_unicode(javascript)
|
def escape_unicode(javascript)
|
||||||
if javascript
|
if javascript
|
||||||
javascript = javascript.dup.force_encoding("utf-8")
|
javascript = javascript.dup.force_encoding("utf-8")
|
||||||
|
|
||||||
|
unless javascript.valid_encoding?
|
||||||
|
# work around bust string with a double conversion
|
||||||
|
javascript.encode!("utf-16","utf-8",:invalid => :replace)
|
||||||
|
javascript.encode!("utf-8","utf-16")
|
||||||
|
end
|
||||||
|
|
||||||
javascript.gsub!(/\342\200\250/u, '
')
|
javascript.gsub!(/\342\200\250/u, '
')
|
||||||
javascript.gsub!(/(<\/)/u, '\u003C/')
|
javascript.gsub!(/(<\/)/u, '\u003C/')
|
||||||
javascript.html_safe
|
javascript.html_safe
|
||||||
|
|
|
@ -2,7 +2,16 @@ require 'spec_helper'
|
||||||
|
|
||||||
describe ApplicationHelper do
|
describe ApplicationHelper do
|
||||||
|
|
||||||
describe 'mobile_view?' do
|
describe "escape_unicode" do
|
||||||
|
it "encodes tags" do
|
||||||
|
helper.escape_unicode("<tag>").should == "\u003ctag>"
|
||||||
|
end
|
||||||
|
it "survives junk text" do
|
||||||
|
helper.escape_unicode("hello \xc3\x28 world").should =~ /hello.*world/
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe "mobile_view?" do
|
||||||
context "enable_mobile_theme is true" do
|
context "enable_mobile_theme is true" do
|
||||||
before do
|
before do
|
||||||
SiteSetting.stubs(:enable_mobile_theme).returns(true)
|
SiteSetting.stubs(:enable_mobile_theme).returns(true)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user