-
Notifications
You must be signed in to change notification settings - Fork 356
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
Conversation
:javascript | ||
miq_tabs_init('#services_tab'); | ||
miq_bootstrap('#service_details', 'sanitizeRender'); | ||
miq_bootstrap('#std_output', 'miq.helpers'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@h-kataria - Just for my understanding as to what this code is doing: is miq_bootstrap
applying miq.helpers
to the div id?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@syncrou i am tying the div that holds standard output to miq_bootstrap object, previously we were attaching the whole outer div but in this case i only need the specific to be attached. miq.helpers
includes ngSanitize directive that is being used.
@syncrou please test/review, also can you please upload a screenshot from the appliance for the Service details screen that was not showing the output prior to this fix. |
@@ -28,7 +28,7 @@ | |||
.form-horizontal.static | |||
.form-group | |||
.col-md-9 | |||
- htm = @job.raw_stdout('html').gsub('"', '\"').gsub("'", "\\\\'") | |||
- htm = @job.raw_stdout('html').gsub('"', '\"').gsub("'", "\\\\'").gsub(/{{/, '\{{').gsub(/}}/, '\}}') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@h-kataria - We'll need this .gsub(/{{/, '\{\{').gsub(/}}/, '\}\}')
(and on line 41) for it to work.
@@ -28,7 +28,7 @@ | |||
.form-horizontal.static | |||
.form-group | |||
.col-md-9 | |||
- htm = @job.raw_stdout('html').gsub('"', '\"').gsub("'", "\\\\'") | |||
- htm = @job.raw_stdout('html').gsub('"', '\"').gsub("'", "\\\\'").gsub(/{{/, '\{\{').gsub(/}}/, '\}\}') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Each gsub
call is going to return a copy of the original string, since these can be large output it would make more sense to do separate gsub!
calls so the substitutions happens without duplicating the string.
There might also be a way to do this in one gsub!
call. For example:
'hello'.gsub(/[eo]/, 'e' => 3, 'o' => '*') #=> "h3ll*"
(See https://ruby-doc.org/core-2.1.4/String.html)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@h-kataria Please add a comment to the description explaining why these characters need to be escaped. Otherwise, I am good with the change.
050e034
to
1dad2ee
Compare
@gmcculloug commit comment has been updated. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I found an issue with sanitize_output
in its current form
@@ -141,6 +141,15 @@ def service_form_fields | |||
|
|||
private | |||
|
|||
def sanitize_output(stdout) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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\') \}\}
@syncrou updated |
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. Have to gsub " on the first line and then gsub for rest of the characters in a one liner works fine. https://bugzilla.redhat.com/show_bug.cgi?id=1451352 https://bugzilla.redhat.com/show_bug.cgi?id=1444853
Checked commit h-kataria@c276603 with ruby 2.2.6, rubocop 0.47.1, and haml-lint 0.20.0 |
👍 👍 (re re) Approve |
Need to gsub occurrences of {{ }} in the output (cherry picked from commit f8fab5e) https://bugzilla.redhat.com/show_bug.cgi?id=1451920 https://bugzilla.redhat.com/show_bug.cgi?id=1446245
Fine backport details:
|
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
@syncrou @gmcculloug please test/review.