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

Conversation

h-kataria
Copy link
Contributor

@h-kataria h-kataria commented May 17, 2017

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.

:javascript
miq_tabs_init('#services_tab');
miq_bootstrap('#service_details', 'sanitizeRender');
miq_bootstrap('#std_output', 'miq.helpers');
Copy link
Contributor

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?

Copy link
Contributor Author

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.

@h-kataria h-kataria changed the title Reverting changes to show html standard output as nice colorful output Need to gsub occurrences of {{ }} in the output May 17, 2017
@h-kataria
Copy link
Contributor Author

@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(/}}/, '\}}')
Copy link
Contributor

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(/}}/, '\}\}')
Copy link
Member

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)

Copy link
Contributor

@syncrou syncrou left a comment

Choose a reason for hiding this comment

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

screen shot 2017-05-17 at 2 16 17 pm

👍 Looks Good to Me

Copy link
Member

@gmcculloug gmcculloug left a 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.

@h-kataria h-kataria force-pushed the stdout_fix branch 2 times, most recently from 050e034 to 1dad2ee Compare May 17, 2017 19:06
@h-kataria
Copy link
Contributor Author

@gmcculloug commit comment has been updated.

Copy link
Contributor

@syncrou syncrou left a 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)
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\') \}\}

@h-kataria
Copy link
Contributor Author

@syncrou updated sanitize_output method

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
@miq-bot
Copy link
Member

miq-bot commented May 17, 2017

Checked commit h-kataria@c276603 with ruby 2.2.6, rubocop 0.47.1, and haml-lint 0.20.0
3 files checked, 0 offenses detected
Everything looks fine. 🍰

@syncrou
Copy link
Contributor

syncrou commented May 17, 2017

👍 👍 (re re) Approve

@dclarizio dclarizio merged commit f8fab5e into ManageIQ:master May 17, 2017
@dclarizio dclarizio added this to the Sprint 61 Ending May 22, 2017 milestone May 17, 2017
simaishi pushed a commit that referenced this pull request May 17, 2017
@simaishi
Copy link
Contributor

Fine backport details:

$ git log -1
commit 1048ffdbd63fdba91023f42efbad4804728ae254
Author: Dan Clarizio <[email protected]>
Date:   Wed May 17 13:51:26 2017 -0700

    Merge pull request #1369 from h-kataria/stdout_fix
    
    Need to gsub occurrences of {{ }} in the output
    (cherry picked from commit f8fab5ea90ab51071663d895e683ef76f0f578f0)
    
    https://bugzilla.redhat.com/show_bug.cgi?id=1451920
    https://bugzilla.redhat.com/show_bug.cgi?id=1446245

@h-kataria h-kataria deleted the stdout_fix branch June 27, 2017 20:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants