1-888-365-2779
+1-888-365-2779
Try Now
More in this section

Forums / Developing with Sitefinity / urlReplaceSymbolRegEx issue

urlReplaceSymbolRegEx issue

9 posts, 1 answered
  1. Richard Baugh
    Richard Baugh avatar
    201 posts
    Registered:
    22 Aug 2012
    09 Mar 2010
    Link to this post
    I am having troubles stripping out a right single quote for titles. I have setup an expression in the web.config file with the following expressions and none of which will strip the character:
    [\W\s\*\?\+\$\.\(\)\[\]\}\|\^\<\>\\~`’,!@#&=':;/%"’]+
    [\W\s\*\?\+\$\.\(\)\[\]\}\|\^\<\>\\~`’,!@#&=':;/%"\u2019;]+
    [\W\s\*\?\+\$\.\(\)\[\]\}\|\^\<\>\\~`’,!@#&=':;/%"\x27;]+

    I have used the following site to build an expression. While the expression works on the site, entering the expression, encoded for XML, to web.config does not.

    We have a client that has an apostrophe in their name and copies and pastes from Word so the characters being pasted are not being stripped and resulting in broken url's. Any help would be appreciated.
  2. Georgi
    Georgi avatar
    3583 posts
    Registered:
    28 Oct 2016
    10 Mar 2010
    Link to this post
    Hi Richard Baugh,

    I have tried to reproduce the problem, but cannot so far. 

    No matter what quotation characters I insert, the links are still working, as well as the URLs. I am using the News module. 

    Can you please paste an example line?

    Is replacing the single quote with underscore sounds like an option?

    All the best,
    Georgi
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
  3. Richard Baugh
    Richard Baugh avatar
    201 posts
    Registered:
    22 Aug 2012
    10 Mar 2010
    Link to this post
    Thanks for helping out. Here is a sample of the character being used. I hope it comes through correctly.

    Copy & Pasted
    David’s Association’s Council on Policy Development

    Manually Typed
    David's Association's Council on Policy development.

    Notice that the copy and paste apostrophe is using a curly apostrophe where as the manually typed line uses a vertical apostrophe. I just opened up MS Word and pasted the value into this editor. Even after the MS stripping, the apostrophe is different than the manually added one. I believe this has to do with the character encoding that is used in the browser vs the encoding used in MS Word.

    The copy & pasted line is what we are having problems with using the "urlReplaceSymbolRegEx " to replace the character with our urlWhiteSpaceChar of "-". When using the apostrophe from the manually typed line above, the regex is catching the character and replacing properly.
  4. Georgi
    Georgi avatar
    3583 posts
    Registered:
    28 Oct 2016
    10 Mar 2010
    Link to this post
    Hello Richard Baugh,

    You are right - this character is not escaped. The urls are working though, here is what I get as a URL when I click on such news item article:

    http://localhost/urls/en/ds/10-03-10/David%E2%80%99s_Association%E2%80%99s_Council_on_Policy_Development.aspx

    I can suggest you the following workaround so far - it will replace all right single quote characters with this one - ' (single, straight):

    Global.asax

    void Application_Start(object sender, EventArgs e)
       {
           Telerik.Cms.Engine.ContentManager.Executing += new EventHandler<Telerik.ExecutingEventArgs>(ContentManager_Executing);
     
       }
     
       void ContentManager_Executing(object sender, Telerik.ExecutingEventArgs e)
       {
           Telerik.Cms.Engine.IContent item = e.CommandArguments as Telerik.Cms.Engine.IContent;
           if (item != null)
           {
               if (e.CommandName == "CreateContent" || e.CommandName == "UpdateContent")
               {
                   string title = item.GetMetaData("Title").ToString();
                   title = title.Replace("’", "'");
                   item.SetMetaData("Title", title);
               }        
           }
       }
    This will work for all content providers, upon saving and updating existing items. 

    The result urls should look like this:

    http://localhost/urls/en/ds/10-03-10/once_again_David_s_Association_s_Council_on_Policy_Development.aspx

    I hope this helps. 

    Greetings,
    Georgi
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
    Answered
  5. Richard Baugh
    Richard Baugh avatar
    201 posts
    Registered:
    22 Aug 2012
    10 Mar 2010
    Link to this post
    Thanks for the reply. I wasn't sure if there was a better RegEx that would capture the character. I will add the workaround to the site. Thanks again for the assistance.

    Just an FYI, the RSS feeds get urlencoded and thus the %e2%80%99 value gets encoded as %27 and therefore the link is broken when trying to click on a rss feed with this character in the url. I should have made myself clearer as I have been working on this from the RSS standpoint where the link is broken.
  6. Georgi
    Georgi avatar
    3583 posts
    Registered:
    28 Oct 2016
    10 Mar 2010
    Link to this post
    Hi Richard Baugh,

    Apologies for ignoring the regex notes.. I got it working without the workaround, using the following regex:

    <add name="News"
     urlReplaceSymbolsRegEx="[\s\*\?\+\$\.\(\)\[\]\}\|\^\<\>\\~`,!@#&=':;/%"‘’]+"

    Please try to use it instead of the workaround. 

    All the best,
    Georgi
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
  7. Georgi
    Georgi avatar
    3583 posts
    Registered:
    28 Oct 2016
    10 Mar 2010
    Link to this post
    Hi Richard Baugh,

    Since the editor here is encoding the characters, please find attached a zip file with a text document, containing the right regex. 

    Best wishes,
    Georgi
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
  8. Richard Baugh
    Richard Baugh avatar
    201 posts
    Registered:
    22 Aug 2012
    10 Mar 2010
    Link to this post
    When I copied the code from the text file into Visual Studio, it changed the character to UTF and the regex is not picking it up and therefore the url is staying with %e2%80%99 and then for the RSS feeds, the character is url encoded to %27.

    When I save the web.config, using notepad, in ANSI format, the characters are changed to a diamond shape with a question mark in the diamond when viewing in Visual Studio. IIS then throws an error when trying to view the page as the web.config is invalid. I am curious as to how you are saving this and getting it to work.

    Attached are three images of the code. One is just opening the regex.txt file you sent in notepad. Then there are two images taken from Visual Studio. One is with the web.config saved in UTF and the other with the web.config saved as ANSI.

    The workaround is working for us, but I would like to be able to use the regular expression. So I'll leave it up to you on whether you have time to keep on with this thread.
  9. Georgi
    Georgi avatar
    3583 posts
    Registered:
    28 Oct 2016
    11 Mar 2010
    Link to this post
    Hi Richard Baugh,

    I think the most practical approach would be to send you my web.config file, which contains the regex. Copy-Paste from it should do the trick.

    All the best,
    Georgi
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
Register for webinar
9 posts, 1 answered