Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

a javascript error is reported on all overrided pages containing javascript with charaters (>,&,<) #229

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion lib/deface/applicator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,16 @@ def apply_overrides(source, overrides:, log: true)
matches.each {|match| override.execute_action match }
end
end

=begin
replace this line of (gem deface)
source = doc.to_s
by source = source = CGI.unescapeHTML doc.to_s
because
doc.class = Nokogiri::HTML::DocumentFragment
and the methode to_s(of nokogiri) use escape_text.
=end
#source = doc.to_s
source = CGI.unescapeHTML doc.to_s

Deface::Parser.undo_erb_markup!(source)

Expand Down
9 changes: 9 additions & 0 deletions spec/deface/applicator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -88,5 +88,14 @@ module Deface
end
end

describe "source containing a javascript tag" do
before { Deface::Override.new(:virtual_path => "posts/index",
:name => "Posts#index",
:remove => "p") }
let(:source) { "<%= javascript_tag do %>if (y > 0) {y = 0;}<% end %>" }
it "should return unmodified source" do
expect(Dummy.apply(source, { :virtual_path => "posts/index" })).to eq("<%= javascript_tag do %>if (y > 0) {y = 0;}<% end %>")
end
end
end
end