Skip to content

Conversation

@SteveL-MSFT
Copy link
Member

New-ModuleManifest was incorrectly checking if a Uri was well formed by using ToString() which just outputs the original string. If the string was a uri with spaces, ToString() doesn't return the escaped version. The AbsoluteUri property should be used instead which returns an escaped absolute uri (if valid).

Also renamed TestModuleManfest.ps1 to TestModuleManifest.Tests.ps1 so that it gets picked up correctly as Pester test.

Since HelpInfoUri is just a string, ensure it is a valid absolute uri and escaped correctly whereas before it was just an opaque string that wasn't validated.

Addresses #3336

Copy link
Contributor

@dantraMSFT dantraMSFT left a comment

Choose a reason for hiding this comment

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

Wrap the return statement in brackets

/// <param name="name">The string to quote</param>
/// <returns>The quoted string</returns>
private string QuoteName(object name)
{
Copy link
Contributor

Choose a reason for hiding this comment

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

The method comments should be updated to reflect string or URI.

Copy link
Member Author

Choose a reason for hiding this comment

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

Will fix

BuildPrivateDataInModuleManifest(result, streamWriter);

BuildModuleManifest(result, "HelpInfoURI", Modules.HelpInfoURI, !string.IsNullOrEmpty(_helpInfoUri), () => QuoteName(_helpInfoUri), streamWriter);
BuildModuleManifest(result, "HelpInfoURI", Modules.HelpInfoURI, !string.IsNullOrEmpty(_helpInfoUri), () => QuoteName((null != _helpInfoUri) ? new Uri(_helpInfoUri) : null), streamWriter);
Copy link
Contributor

Choose a reason for hiding this comment

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

This statement is getting rather convoluted. Suggest breaking out the QuoteName logic for readability.

Copy link
Member Author

Choose a reason for hiding this comment

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

Since QuoteName() takes a null but Uri constructor doesn't accept null, I think we'd end up with a bunch of code that makes it harder to read in this particular case.

Dbg.Assert(!String.IsNullOrWhiteSpace(parameterName), "parameterName should not be null or whitespace");

if (uri != null && !Uri.IsWellFormedUriString(uri.ToString(), UriKind.Absolute))
if (uri != null && !Uri.IsWellFormedUriString(uri.AbsoluteUri, UriKind.Absolute))
Copy link
Contributor

Choose a reason for hiding this comment

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

You're using inconsistent comparison to null ordering. (i.e., value != null versus null != value). Suggest picking one.

Copy link
Member Author

Choose a reason for hiding this comment

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

I prefer null on the left, but most of the code in this file has it on the right, I'll change my usage to make it consistent

{
if (name == null)
return "''";
else if (name is Uri)
Copy link
Contributor

Choose a reason for hiding this comment

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

Avoid casting multiple times. consider assigning name as Uri and testing for null.

Copy link
Member Author

Choose a reason for hiding this comment

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

In this case, name may or may not be a Uri. I'm special casing when it is a Uri, I want to use the AbsoluteUri member value.

/// <param name="name">The string to quote</param>
/// <returns>The quoted string</returns>
private string QuoteName(object name)
{
Copy link
Contributor

Choose a reason for hiding this comment

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

The method comments should be updated to reflect string or URI. Better would be to have two explicit overloads and remove the 'object' overload since I don't think anything other than uri and string are expected.

Copy link
Member Author

Choose a reason for hiding this comment

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

I looked through the calls to QuoteName() and I believe you are right that it's only a string or Uri. I'll separate it.

Copy link
Member Author

Choose a reason for hiding this comment

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

Actually Version is another type that needs to be supported

@SteveL-MSFT SteveL-MSFT force-pushed the new-modulemanifest-uri branch 3 times, most recently from 3c75047 to 5adb431 Compare April 25, 2017 20:19
…by using ToString() which just outputs the original

string.  If the string was a uri with spaces, ToString() doesn't return the escaped version.  The AbsoluteUri property
should be used instead which returns an escaped absolute uri (if valid).

Also renamed TestModuleManfest.ps1 to TestModuleManifest.Tests.ps1 so that it gets picked up correctly as Pester test.

Since HelpInfoUri is just a string, ensure it is a valid absolute uri and escaped correctly whereas before it was just
an opaque string that wasn't validated.
@SteveL-MSFT SteveL-MSFT force-pushed the new-modulemanifest-uri branch from 5adb431 to 5017f79 Compare April 25, 2017 20:57
@SteveL-MSFT SteveL-MSFT assigned mirichmo and unassigned TravisEz13 Apr 25, 2017
@mirichmo mirichmo merged commit ee9049b into PowerShell:master Apr 26, 2017
@SteveL-MSFT SteveL-MSFT deleted the new-modulemanifest-uri branch April 26, 2017 16:52
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.

5 participants