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

Need to gsub occurrences of {{ }} in the output #1369

Merged
merged 1 commit into from
May 17, 2017
Merged
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
13 changes: 13 additions & 0 deletions app/controllers/service_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,19 @@ def service_form_fields

private

def sanitize_output(stdout)
Copy link
Contributor

@syncrou syncrou May 17, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

    htm = stdout.gsub('"', '\"')
    htm.gsub!("'", "\\\\'")
    htm.gsub!(/{{/, '\{\{')
    htm.gsub!(/}}/, '\}\}')
    htm

This is actually a copy of the gsub pattern that will work.

The files coming back from Ansible are prefixing {{ with a " which needs to be escaped first before we can gsub! on the returned string. Angular is blowing up on the {{ which also need to be escaped. Not sure this solution is the most efficient - but it is the exact code running on the appliance that allows the output to show.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The substitution needs to change: u\"{{ manageiq_mach | default('localhost') }}\" into \{\{ manageiq_mach | default(\'localhost\') \}\}

htm = stdout.gsub('"', '\"')

regex_map = {
/'/ => "\\\\'",
/{{/ => '\{\{',
/}}/ => '\}\}'
}
regex_map.each_pair { |f, t| htm.gsub!(f, t) }
htm
end
helper_method :sanitize_output

def textual_group_list
if @record.type == "ServiceAnsiblePlaybook"
[%i(properties), %i(lifecycle tags)]
Expand Down
6 changes: 2 additions & 4 deletions app/views/service/_svcs_show.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@
.form-horizontal.static
.form-group
.col-md-9
- htm = @job.raw_stdout('html').gsub('"', '\"').gsub("'", "\\\\'")
%div{'ng-bind-html'=>"vm.sanitizeRenderHtml('#{htm}')"}
%div{'ng-bind-html'=>"vm.sanitizeRenderHtml('#{sanitize_output(@job.raw_stdout('html'))}')"}
- if job
= miq_tab_content("retirement", 'default', :class => 'cm-tab') do
= render :partial => "layouts/textual_groups_tabs", :locals => {:textual_group_list => textual_retirement_group_list}
Expand All @@ -52,8 +51,7 @@
.form-horizontal.static
.form-group
.col-md-9
- htm = job.raw_stdout('html').gsub('"', '\"').gsub("'", "\\\\'")
%div{'ng-bind-html'=>"vm.sanitizeRenderHtml('#{htm}')"}
%div{'ng-bind-html'=>"vm.sanitizeRenderHtml('#{sanitize_output(job.raw_stdout('html'))}')"}
:javascript
miq_tabs_init('#services_tab');
miq_bootstrap('#service_details', 'sanitizeRender');
7 changes: 7 additions & 0 deletions spec/controllers/service_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,5 +79,12 @@
end
end

context "#sanitize_output" do
it "escapes characters in the output string" do
output = controller.send(:sanitize_output, "I'm \"Fred\" {{Flintstone}}")
expect(output).to eq("I\\'m \\\"Fred\\\" \\{\\{Flintstone\\}\\}")
end
end

it_behaves_like "explorer controller with custom buttons"
end