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 (>,&,<) #230

Open
mathieu-mbru opened this issue Mar 16, 2022 · 3 comments

Comments

@mathieu-mbru
Copy link

Hello

a javascript error is reported on all overrided pages containing javascript with charaters (>,&,<)
Example
image
image
image
We have identified the cause that breaks the javascript code (which is encoded).
The cause is the following:
The view source or partial of type (Nokogiri::HTML::DocumentFragment) which encodes characters by calling the method to_s in (Module Applicator /method apply_overrides ) line 52 (source = doc.to_s) :
image
Since we trust views files and partials,
By replace this line :
source = doc.to_s
by this one :
source = doc.to_s.gsub('&lt;', '<').gsub('&gt;', '>').gsub('&amp;', '&')
The problem no longer exists
A PR was carried out on the subject #229
Thank you for considering this update.

@nanego
Copy link

nanego commented Mar 17, 2022

Hello @mathieu-mbru
I managed to reproduce the issue.
Here is a failing test. Please feel free to include it in your patch:

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
expected: "<%= javascript_tag do %>if (y > 0) {y = 0;}<% end %>"
     got: "<%= javascript_tag do %>if (y &gt; 0) {y = 0;}<% end %>"

@mathieu-mbru
Copy link
Author

Ok, thank you

@salmanmp
Copy link

very good. related to #224

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants