Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Clem 6 posts 26 karma points
    Jan 16, 2012 @ 17:12
    Clem
    0

    Outputting a querystring value that includes an encoded character

    I'm really struggling to display an encoded value that comes from a querystring correctly and would appreciate any help...

    The best way to describe this is with an example:

    When a user clicks on link that includes a non-standard letter (e.g. รก) in the querystring this is encoded in the URL (e.g. as %E1).

    In an XSLT macro when I read the querystring value using either

    <xsl:variable name="Country" select="/macro/Country"/> from template call <umbraco:Macro Country="[@c]" Alias="Test" runat="server"></umbraco:Macro> or
    <xsl:variable name="Country" select="umbraco.library:RequestQueryString('c')"/>

    and output the value as

    <xsl:value-of select="$Country" disable-output-escaping="yes"/> or
    <xsl:value-of select="$Country" disable-output-escaping="no"/>

    The value on the web page (and in the source) is a diamond character with a ? in it (this happens for all encoded characters).

    I've set HTML encoding to UTF-8 using <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    and set the XSLT encoding to UTF-8 using <?xml version="1.0" encoding="UTF-8"?>

    What am i doing incorrectly?

  • Rodion Novoselov 694 posts 859 karma points
    Jan 16, 2012 @ 17:22
    Rodion Novoselov
    0

    Hi. I would also try to set the "system.web/globalization/responseEncoding" setting in your "web.config" file to "utf-8".

  • Clem 6 posts 26 karma points
    Jan 16, 2012 @ 17:24
    Clem
    0

    Thanks Rodion,

    The web config already has the encoding as UTF-8

    <globalization requestEncoding="UTF-8" responseEncoding="UTF-8" />

  • Chriztian Steinmeier 2800 posts 8790 karma points MVP 8x admin c-trib
    Jan 16, 2012 @ 17:57
    Chriztian Steinmeier
    2

    Hi Clem,

    If the character in the page displays as a question mark, it's because the browser interprets the character "wrong" according to what the webpage reports - which there can be a couple of reasons for:

    1. The browser's encoding setting is wrong (e.g. could be set to force US-ASCII or some other).

    2. The page is actually reporting the wrong encoding - if I remember correctly the server setting overrules the meta - so check the Content-Type header from the server (using redbot.org or similar tool).

    Regarding the XSLT file: the pseudo-attribute "encoding" in the XML declaration does nothing other than give the parser a hint at the character encoding of an XML file. If the file is saved in another encoding from an editor you will get some of the same situations, even though you think you've covered your bases. It's very important to make sure that the editor actually saves in UTF-8.

    This shouldn't be a problem with URL encoding - as long as you get the value using either of the methods you state (RequestQueryString() or Advanced Macro Syntax).

    /Chriztian

  • Clem 6 posts 26 karma points
    Jan 16, 2012 @ 19:28
    Clem
    0

    Thanks Chriztian,

    1. I've checked the encoding on my browser and it was set to UTF-8 for the relevant page - the error also occurs on at least 20 different browsers in different environments so it seems unlikely.

    2. rebot is reporting that the charset is UTF-8. So this seems ok.

    3. I'm away from my desktop and will check the encoding on XML-Spy in the morning, but i've tried editing the XSL with Umbraco CMS and in notepad (with encoding as UTF-8) and neither helped after saving.

    Can URL rewrite or something else in IIS possibly be causing this?

    When i output the entire querystring in the XSLT it outputs correctly as an encoded URL (e.g. c=Par%E1) so it seems as though the inbuilt function on the server that decodes the querystring attibute may be causing the issue?

  • Chriztian Steinmeier 2800 posts 8790 karma points MVP 8x admin c-trib
    Jan 16, 2012 @ 20:32
    Chriztian Steinmeier
    0

    Hi Clem,

    I'm leaning a towards the URL Rewrite now - If you output a value you got from RequestQueryString, it shouldn't show as encoded - it should have been correctly decoded - regardless of server software etc. so there's definitely something wrong there.

    /Chriztian

     

  • Clem 6 posts 26 karma points
    Jan 17, 2012 @ 14:38
    Clem
    0

    Hi Chriztian,

    Thanks for your help again!

    I'm stumped as how best to continue and have already spent way to much time trying to resolve this, so will implement a work-around instead.

    Cheers,
    Clem

Please Sign in or register to post replies

Write your reply to:

Draft