Skip to content

Commit

Permalink
Need to gsub occurrences of {{ }} in the output
Browse files Browse the repository at this point in the history
Moved gsub logic into a helper method. Having ", ', {{, }} characters in the output was causing an issue while rendering html using ngSanitize directive, needed to escape these characters to get the output to be displayed correctly on screen.

https://bugzilla.redhat.com/show_bug.cgi?id=1451352
https://bugzilla.redhat.com/show_bug.cgi?id=1444853
  • Loading branch information
h-kataria committed May 17, 2017
1 parent 7ee8f63 commit 1dad2ee
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
9 changes: 9 additions & 0 deletions app/controllers/service_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,15 @@ def service_form_fields

private

def sanitize_output(stdout)
stdout.gsub!('"', '\"')
stdout.gsub!("'", "\\\\'")
stdout.gsub!(/{{/, "\{\{")
stdout.gsub!(/}}/, "\}\}")
stdout
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

0 comments on commit 1dad2ee

Please sign in to comment.