GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
GeezerVison is showing github.com — Added Meta, Charset, and Transitional parameters to ConvertTo-HTML by ergo3114 · Pull Request #4184 · PowerShell/PowerShell Conversation
|
|
Littlejohn (@ergo3114), |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| { | ||
| if(s != "content-type" && s != "default-style" && s !="refresh") | ||
| { | ||
| WriteObject("<meta name=\"" + s + "\" content=\"" + _meta[s] + "\">"); |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
should we encode the key and value?
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
What would encoding gain us here? I am not familiar with that.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| WriteObject("<head>"); | ||
| if(_charsetSpecified) | ||
| { | ||
| WriteObject("<meta charset=\"" + _charset + "\">"); |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Should probably validate or encode the character set.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Validation would be great. I don't see too many changes in the charset list but it would be great if the validation were dynamic pulling from w3schools or something. I was trying to find documentation on what the browser does when a non standard charset is specified; such as "foo". I believe it analyzes the html and determines the best or just defaults to UTF-8 for HTML5.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
I'm sure there are illegal characters. Even a validation that validates the user hasn't specified something illegal would be better than nothing.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
I will put something in and resubmit it.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| WriteObject("<meta name=\"" + s + "\" content=\"" + _meta[s] + "\">"); | ||
| } | ||
| else { | ||
| WriteObject("<meta http-equiv=\"" + s + "\" content=\"" + _meta[s] + "\">"); |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Should we allow these or should it be another parameter like charset
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
It looks like you can validate the meta tag. w3schools shows the schema for the meta tag.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Could you use ValidatePattern or ValidateScript to implement it? https://blogs.technet.microsoft.com/heyscriptingguy/2011/01/11/validate-powershell-parameters-before-running-the-script/
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
James Truher (@JamesWTruher) Can you review the character set parameter here? |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR. I have a couple of comments. Please review and respond.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
- Set the output of Charset to upper case if a lowercase value is given
| } | ||
| set | ||
| { | ||
| _meta = value; |
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
I believe the typical pattern is to use InvocationInfo.BoundParameters. This would then allow you to use the automatic properties to simplify the code a bit
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
I was unable to get InvocationInfo.BoundParameters to work. I read over InvocationInfo.cs and ImplicitRemotingCommands.cs to see if I can make sense of it but I am at a loss here.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
We can use an auto property and Meta == null to check if user assign a value.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
That should be fine, too
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Littlejohn (@ergo3114) Please address this.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
I see this as two ways to do the same thing. What are you looking to gain from setting a default value versus checking a flag? Just curious.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
A quick search shows we already have inconsistency so I'm fine staying with this pattern
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| { | ||
| foreach(string s in _meta.Keys) | ||
| { | ||
| if(s == "content-type" && s == "default-style" && s =="refresh") |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't this be ||? In any case, there's more http-equiv than this list. Perhaps we should just have a separate parameter for http-equiv meta tags and let the user put whatever they want in it? Also, I believe the names are case-insensitive so Content-Type is valid.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
This has been changed.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| /// Specifies the charset encoding for the HTML document | ||
| /// </summary> | ||
| [Parameter(ParameterSetName = "Page")] | ||
| [ValidateNotNullOrEmpty] |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Technically, the allowed set of (legacy) encodings is quite large although HTML5 I believe has standardized on UTF-8. So perhaps this shouldn't have a ValidateSet?
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
I have removed to the ValidateSet.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Please add some tests
Sorry, something went wrong.
There was an error while loading. Please reload this page.
- Removed Validateset from Charset parameter to allow for legacy character sets - Added test for Meta, Charset, and Transitional property on ConvertTo-HTML command
| } | ||
| set | ||
| { | ||
| _meta = value; |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
We can use an auto property and Meta == null to check if user assign a value.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| } | ||
| set | ||
| { | ||
| _charset = value.ToUpper(); |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Why do we convert a charset to upper case?
It seems we can remove this and use auto property.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Closed.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| } | ||
| set | ||
| { | ||
| _transitional = value; |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
We can use an auto property for a switch parameter without getter/setter.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
…meter - Removed private variable for transitional switch parameter - Removed toUpper() functin from charset
- Set meta hashtable keys to lower before checking in switch statement - Updated test for the transitional parameter to check only the first line of the result - Updated test to be more specific on the error message that is returned when thrown - Added logic to prevent duplicate meta tags
| /// </summary> | ||
| /// <returns></returns> | ||
| [Parameter(ParameterSetName = "Page")] | ||
| [ValidateNotNullOrEmpty] |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
I think you want { get; set; } here instead of a field.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| break; | ||
| } | ||
| useditems.Add(s); | ||
| } |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
seems like we should give a warning if we are dropping duplicates
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
I have changed it to a warning and decided to keep the meta tags that don't match the switch.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| ThrowTerminatingError (new ErrorRecord(exc, "MetaPropertyNotFound", ErrorCategory.ParserError, null)); | ||
| //Exception exc = new NotSupportedException(StringUtil.Format(ConvertHTMLStrings.MetaPropertyNotFound, s)); | ||
| MshCommandRuntime mshCommandRuntime = this.CommandRuntime as MshCommandRuntime; | ||
| string Message = "Accepted meta properties are content-type, default-style, application-name, author, description, generator, keywords, x-ua-compatible, and viewport. The meta pair: " + s + " and " + _meta[s] + " may not function correctly."; |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Add a new string in the resx file so that it can be localized
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| It "Test ConvertTo-HTML meta with invalid properties should throw"{ | ||
| { ($customObject | ConvertTo-HTML -Meta @{"authors"="John Doe";"keywords"="PowerShell,PSv6"}) -join $newLine } | Should Throw "authors is not a supported meta property. Accepted meta properties are content-type, default-style, application-name, author, description, generator, keywords, x-ua-compatible, and viewport." | ||
| It "Test ConvertTo-HTML meta with invalid properties should throw warning" { | ||
| ($customObject | ConvertTo-HTML -Meta @{"authors"="John Doe";"keywords"="PowerShell,PSv6"} 3>&1) -match "Accepted meta properties are" | Should Be $true |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Since the message could be localized, you probably just need to check that the warning contains the Meta tags you used in the test
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| } | ||
|
|
||
| It "Test ConvertTo-HTML meta with invalid properties should throw warning" { | ||
| ($customObject | ConvertTo-HTML -Meta @{"authors"="John Doe";"keywords"="PowerShell,PSv6"} 3>&1) -match "Accepted meta properties are" | Should Be $true |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Since the warning message can be localized, you shouldn't check against the English string. Instead, check that the warning message contains the meta pair.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
…ters to ConvertTo-HTML (PowerShell#4184) (reverted from commit bbc180a)
…ll#4881) That PR incorrectly included Pester changes. Most likely because that individual did not update his submodules.
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
There was an error while loading. Please reload this page.