Skip to content

Conversation

@iSazonov
Copy link
Collaborator

@iSazonov iSazonov commented Sep 13, 2018

PR Summary

Fix #7693.

Add EscapeHandling parameter in ConvertTo-Json cmdlet to allow escape the HTML (<, >, &, ', ") and control characters (e.g. newline).

PR Checklist

@iSazonov iSazonov added the Documentation Needed in this repo Documentation is needed in this repo label Sep 13, 2018
@iSazonov iSazonov self-assigned this Sep 13, 2018
@iSazonov
Copy link
Collaborator Author

/cc @PlagueHO @mkht @markekraus

@PlagueHO
Copy link

Great solution - thanks @iSazonov - really appreciate it. 🏆

@iSazonov iSazonov force-pushed the convertto-json-escapehandling branch 2 times, most recently from d2e6719 to 1af310d Compare September 13, 2018 09:39
@iSazonov
Copy link
Collaborator Author

@TravisEz13 Should CI Travis be removed?

@TravisEz13
Copy link
Member

@iSazonov Yes, it is now replaced with the PowerShell-CI-linux and PowerShell-CI-macos

Copy link
Member

Choose a reason for hiding this comment

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

Turn this into -TestCases? Benefit is if first assert fails, the whole thing doesn't fail.

@iSazonov iSazonov force-pushed the convertto-json-escapehandling branch from 3ff21c6 to 4cf4378 Compare September 17, 2018 11:24
Copy link
Member

Choose a reason for hiding this comment

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

Is there a reason for this change from using the verbose channel to know that the cmdlet has started to a sleep? On a particularly slow container/VM, it might take longer than 300ms.

Copy link
Collaborator Author

@iSazonov iSazonov Sep 18, 2018

Choose a reason for hiding this comment

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

We removed the verbose message in #7487 and currently the test take 10 seconds until timeout.
We could consider adding debug message instead of the verbose message.

Copy link
Member

Choose a reason for hiding this comment

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

@iSazonov ok, got it. Seems like the right thing to do would be to have some test hook so that we can make this predictable as anything with small timeouts are more likely to fail in CI especially when it's under load.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I added verbose in BeginProcessing(). (Previously it was in ProcessRecord())

Copy link
Member

Choose a reason for hiding this comment

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

Per comment on line 33, Stop() is synchronous and in the chance it blocks, Pester is blocked. Perhaps we can change the sleep on line 34 to Wait-UntilTrue where State changes?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I think we could discuss this in #7819 and perhaps remove the tests at all.

Copy link
Member

Choose a reason for hiding this comment

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

If you can revert changes to this test in this PR, I think we can move forward with this PR and resolve this test in the other PR.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Reverted in the PR and moved to #7819.

@iSazonov iSazonov force-pushed the convertto-json-escapehandling branch from 24ffde6 to 7ef9f10 Compare September 20, 2018 07:52
@iSazonov iSazonov force-pushed the convertto-json-escapehandling branch from 6df405a to 7ef9f10 Compare September 20, 2018 08:13
@iSazonov
Copy link
Collaborator Author

Reopen to restart PowerShell-CI-Linux.

$obj = [PSCustomObject]@{P1 = ''; P2 = ''; P3 = ''; P4 = ''; P5 = ''; P6 = ''}
$obj.P1 = $obj.P2 = $obj.P3 = $obj.P4 = $obj.P5 = $obj.P6 = $obj
1..100 | Foreach-Object { $obj } | ConvertTo-Json -Depth 10 -Verbose
1..100 | Foreach-Object { $obj } | ConvertTo-Json -Depth 10
Copy link
Member

Choose a reason for hiding this comment

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

Surprised this test passed if you remove -verbose as line 35 is waiting on verbose output?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The waiting take 10 seconds until timeout.

Copy link
Member

Choose a reason for hiding this comment

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

You are removing -Verbose because another PR removed the verbose message (which you added back with the test hook in the other PR), right? If so, I suppose this is ok, but it seems this change doesn't have any impact to this test so wondering why have this change in this PR at all?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Reverted the change.

$obj = [PSCustomObject]@{P1 = ''; P2 = ''; P3 = ''; P4 = ''; P5 = ''; P6 = ''}
$obj.P1 = $obj.P2 = $obj.P3 = $obj.P4 = $obj.P5 = $obj.P6 = $obj
1..100 | Foreach-Object { $obj } | ConvertTo-Json -Depth 10 -Verbose
1..100 | Foreach-Object { $obj } | ConvertTo-Json -Depth 10
Copy link
Member

Choose a reason for hiding this comment

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

You are removing -Verbose because another PR removed the verbose message (which you added back with the test hook in the other PR), right? If so, I suppose this is ok, but it seems this change doesn't have any impact to this test so wondering why have this change in this PR at all?

@iSazonov
Copy link
Collaborator Author

@daxian-dbw @dantraMSFT Could you please do (fast) review before we merge?

Copy link
Contributor

@markekraus markekraus left a comment

Choose a reason for hiding this comment

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

LGTM

@iSazonov iSazonov merged commit d862d40 into PowerShell:master Oct 2, 2018
@iSazonov iSazonov deleted the convertto-json-escapehandling branch October 2, 2018 05:54
@joeyaiello joeyaiello removed Documentation Needed in this repo Documentation is needed in this repo labels Oct 15, 2018
adityapatwardhan pushed a commit to adityapatwardhan/PowerShell that referenced this pull request Apr 9, 2019
Add EscapeHandling parameter in ConvertTo-Json cmdlet to allow escape the HTML (<, >, &, ', ") and control characters (e.g. newline).
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

Successfully merging this pull request may close these issues.

ConvertTo-Json string escaped handling differs between PS and PSCore

6 participants