SharePoint 2013 : The search results with %5C (the “\” character) will become double encoded and causes broken links

SharePoint 2013 : The search results with %5C (the “\” character) will become double encoded and causes broken links

Rate This
  • Comments 8

 

Use Case Description: The search results with %5C (the “\” character) will become double encoded (represented as “%255C″). This causes broken links for e.g. when accessing Search Center and performing people search with "user1". At the peopleresults.aspx page, click the username in the search result

Actual Results: The personal site of user1 cannot be accessed. You can see the personal site for user1 is something like below

http://sp2013.contoso.com/my2/Person.aspx?accountname=contoso%255Cuser1

 

 

Workaround Instructions: Apply below workaround on current search center site. If you have additional search center sites, please update all of them.

1. On your Search Center site collection go to Site Settings and then Master Page Gallery

2. On Master Page Gallery click on Display Templates and then click on Search

                      Now find File named Item_Person.html and then checkout the file. Make a backup of the file and open the file in your favorite text editor and locate highlighted Line in below Screenshot.

 

image

3. Now replace above highlighted line replace with following text.

var encodedPath = $urlHtmlEncode(decodeURI(ctx.CurrentItem.Path));

4. Now find File named Item_Person_CompactHorizontal.html and then checkout the file. Make a backup of the file and open the file in your favorite text editor and then locate highlighted Line in below Screenshot.

image

 

5. Now replace above highlighted line replace with following text.

              var pathEncoded = $urlHtmlEncode(decodeURI(ctx.CurrentItem.Path));

 

6. Now find File named Item_Person_HoverPanel.html and then checkout the file. Make a backup of the file and open the file in your favorite text editor and then locate highlighted Line in below Screenshot.

 

image

                 Now replace above highlighted line so that it looks like following.

<a id="_#= visitId =#_" class="ms-calloutLink ms-uppercase" href="_#= $urlHtmlEncode(decodeURI(ctx.CurrentItem.Path)) =#_" title="_#= $htmlEncode(Srch.Res.hp_PeopleItem_ViewProfile) =#_">

7. Now check-in the above files and make sure they are published.

Note:  This issue is now fixed as described in http://support.microsoft.com/kb/2883088 , Which is included in Sep 2014 CU for SharePoint 2013

 

POST BY: Srinivas Dutta [MSFT]

Leave a Comment
  • Please add 6 and 8 and type the answer here:
  • Post
  • I've provided a more global fix (as this doesn't occur with just People searches and Display Templates are Site Collection scope) available at thesharepointfarm.com/.../workaround-ms14-022-double-encoding-bug. Technically, the global fix is also easier to revert when an official fix is released.

  • Although the proposed workaround of updating JS files may work for the customers, changing the JS file will make the deployment ‘un-patchable’ in a sense and patches will not be able to update a system that has undergone such a change.

    Editing the OOB Javascript files is not supported by Product Support & services.

  • Looks like your screenshots are out of sync with your text. I supposed third screenshot is really for step 6.

    In addition, I found 2 instances of the line referenced in steps 4 and 5.

    For those reading these steps to the letter or people like me (on auto-pilot when it's late), might I suggest adding that at step 7, Upload the file before check-in.

  • Will this affect the "Show More" link on search results where Hybrid is configured. I do see this behavior because when i search for * and click show more it is being translated into tenant.sharepoint.com/.../results.aspx.  

  • Is this issue resolved with the combination of July and August patches?

  • Good work around, Thanks, Editing OOB js was not an option for us.

    We use OOB search center, I resolved this by adding a Script Editor webpart to results.aspx with following script

    <script language="javascript">

    function customSearchResultsFixUrlEncoding(str, find, replace) {

     return str.replace(new RegExp(find, 'g'), replace);

    }

    $('.ms-searchCenter-result-main').on("click", "a", function (event) {

    var url= $(this).attr('href');

    var url2 = customSearchResultsFixUrlEncoding(url, "%2520", "%20");

    var url2 = customSearchResultsFixUrlEncoding(url2, "%255C", "%5C");

    var url2 = customSearchResultsFixUrlEncoding(url2, "%252E", "%2E");

    $(this).attr('href', url2);

    });

    </script>

  • As Fred B mentioned, there is something missing in this fix regarding the Item_Person_CompactHorizontal.html file. The line referenced in step 4 must be changed, but the line referenced in step 2 also appears in the Item_Person_CompactHorizontal.html file, and the updated line provided in step 3 must also be applied to that file. Step 5 should be updated to include this.

    Note that there is a slight difference between those lines... in step 3 it is "var encodedPath" and in step 5 it is "var pathEncoded". If you put them in the wrong place People Search will stop working entirely.

  • This issue has been addressed through permanent fix now. Please contact Microsoft support if you require permanent fix info.

Page 1 of 1 (8 items)