pnp / pnpframework

PnP Framework is a .NET library targeting Microsoft 365 containing the PnP Provisioning engine and a ton of other useful extensions
https://pnp.github.io/pnpframework/
MIT License
211 stars 145 forks source link

New-PnPSite removing full stops/periods from Alias/URL #759

Open kdfarquharson opened 2 years ago

kdfarquharson commented 2 years ago

When creating a new site with full stops in the Alias these are removed. Sites can be created manually through the SharePoint UI with full stops in their URL. The associated group retains the full stops in its name.

Steps to recreate: $adminsString = 'Adminn@TenantName.onmicrosoft.com' $siteName = 'New site with Full Stops.' $siteAlias = 'GBL.SharePoint.FullStop.Test' $SiteDescription = 'Site Description' $newSite = New-PnPSite -Type TeamSite -Title $SiteName -Alias $SiteAlias -Description $SiteDescription -Owners $adminsString $newSite https://TenantName.sharepoint.com/sites/GBLSharePointFullStopTest

The following site can be created in the tenant from the SharePoint admin page: https://TenantName.sharepoint.com/sites/Test.Full.Stops/SitePages/Home.aspx

Source - it appears to be from the PnPFramework\Sites\SiteCollection.cs file (this call or one of the similar ones):

            string siteCollectionValidAlias = siteCollectionCreationInformation.Alias;
            siteCollectionValidAlias = UrlUtility.RemoveUnallowedCharacters(siteCollectionValidAlias);
            siteCollectionValidAlias = UrlUtility.ReplaceAccentedCharactersWithLatin(siteCollectionValidAlias);

Which goes to PnP.Framework\Utilities\UrlUtility.cs

        public static string RemoveUnallowedCharacters(string str)
        {
            const string unallowedCharacters = "[&,!@;:#¤`´~¨='%<>/\\\\\"\\.\\$\\*\\^\\+\\|\\{\\}\\[\\]\\(\\)\\?\\s]";
            var regex = new Regex(unallowedCharacters);
            return regex.Replace(str, "");
        }

Which removes the full stops.

As I'm new to PnP & Github what's the best way to resolve this? I'm not sure where else RemoveUnallowedCharacters is called from or for what purpose so don't want to just remove the dot replacement from the regex as it might be required elsewhere: const string unallowedCharacters = "[&,!@;:#¤´~¨='%<>/\\\"\$\*\^\+\|\{\}\[\]\(\)\?\s]";`

kdfarquharson commented 2 years ago

There are 6 references to the RemoveUnallowedCharacters in PnP.Framework 2 in ObjectHandlers\ObjectHierarchySequenceSites.cs 1 in ObjectHandlers\ObjectTeams.cs 3 in Sites\SiteCollection.cs 5 refer to Alias, 1 (in ObjectTeams.cs) refers to MailNickname, which is related to Alias. Both Alias and MailNickName can have full stops in them in the UI Would it therefore be acceptible to update the existing RemoveUnallowedCharacters method to take out the removal of full stops? Does anyone know why it removes full stops?