Copied to clipboard

Flag this post as spam?

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


  • Wesley de Roo 38 posts 142 karma points
    May 20, 2014 @ 16:10
    Wesley de Roo
    0

    Getcropurl escapping ampersand

    When validating my site I get errors on the way the querstring for getCropUrl is formatted.

    …dia/9628/aspergesoep.jpg?anchor=center&mode=crop&quality=65&width=152&height=1…

    & did not start a character reference. (& probably should have been escaped as &.)

    Is there a way to change this

    Thanks in advance

  • Jeavon Leopold 3074 posts 13632 karma points MVP 11x admin c-trib
    May 20, 2014 @ 16:33
    Jeavon Leopold
    0

    Hi Wesley,

    Can you post how you are outputting the image url?

    Razor will normally automatically escape the ampersands. If you view source on the page, it should look something like this: "/media/1005/contact.jpg?center=0.43333333333333335,0.49746192893401014&mode=crop&quality=90&width=768&heightratio=0.76171875&slimmage=true&rnd=130432563170000000"

    Jeavon

  • Wesley de Roo 38 posts 142 karma points
    May 20, 2014 @ 16:40
    Wesley de Roo
    0
    <div id="ri-grid" class="ri-grid ri-grid-size-1">
        <ul>
        @if (Model.Content.HasValue("selecteerProducts")) {
                var chosenMedia = Umbraco.TypedMedia(Model.Content.GetPropertyValue("selecteerProducts"));
                if (chosenMedia.DocumentTypeAlias == "Image") {
                <img src="@chosenMedia.GetCropUrl(propertyAlias: "umbracoFile", width: 152, height: 152, quality: 65)" />
                } else if (chosenMedia.DocumentTypeAlias == "Folder") {
                    foreach (var img in chosenMedia.Children.RandomOrder().Take(30)) {
                        @Html.Raw("<li class=\"row" + rowNr + " column" + columnNr + " nr" + count + "\"><a href=\"" + Model.Content.GetPropertyValue("linkNaarDeWebshop", true) + "\" target=\"_blank\"><img src=\"" + img.GetCropUrl(propertyAlias: "umbracoFile", width: 152, height: 152, quality: 65) + "\" alt=\"" + img.Name + "\" />");
                        @Html.Raw("<div class=\"caption\">" + img.GetPropertyValue("productnaam") + "</div>");
                        //@Html.Raw("<div class=\"linkShop\"></div>");
                        @Html.Raw("</a></li>");
                        if (columnNr < listColumns) {
                            columnNr++;
                        } else {
                            columnNr = 1;
                            if (rowNr < listColumns) {
                                rowNr++;
                            } else {
                                rowNr = 1;
                            }
                        }
                        count++;
                    }
                }
            }
        </ul>
    </div>
    

    gives me:

    <ul>
    <li class="row1 column1 nr1"><a href="#" target="_blank"><img src="/media/11452/narcis_keramiek_ei.jpg?anchor=center&mode=crop&quality=65&width=152&height=152&rnd=130396236320000000" alt="Narcis Keramiek Ei" /><div class="caption"></div></a></li><li class="row1 column2 nr2"><a href="#" target="_blank"><img src="/media/11454/paasbrood.jpg?anchor=center&mode=crop&quality=65&width=152&height=152&rnd=130396236330000000" alt="Paasbrood" /><div class="caption"></div></a></li><li class="row1 column3 nr3"><a href="#" target="_blank"><img src="/media/11453/paas-plateau.jpg?anchor=center&mode=crop&quality=65&width=152&height=152&rnd=130396236320000000" alt="Paas Plateau" /><div class="caption"></div></a></li><li class="row2 column1 nr4"><a href="#" target="_blank"><img src="/media/9634/campina_milk_fruit.jpg?anchor=center&mode=crop&quality=65&width=152&height=152&rnd=130362644430000000" alt="Campina Milk Fruit" /><div class="caption"></div></a></li><li class="row2 column2 nr5"><a href="#" target="_blank"><img src="/media/11457/paasservet.jpg?anchor=center&mode=crop&quality=65&width=152&height=152&rnd=130396236350000000" alt="Paasservet" /><div class="caption"></div></a></li><li class="row2 column3 nr6"><a href="#" target="_blank"><img src="/media/9663/tulpen_oranje.jpg?anchor=center&mode=crop&quality=65&width=152&height=152&rnd=130450541530000000" alt="Tulpen Oranje" /><div class="caption"></div></a></li><li class="row3 column1 nr7"><a href="#" target="_blank"><img src="/media/9621/3vaks_asperges.jpg?anchor=center&mode=crop&quality=65&width=152&height=152&rnd=130362644330000000" alt="3Vaks Asperges" /><div class="caption"></div></a></li><li class="row3 column2 nr8"><a href="#" target="_blank"><img src="/media/9622/3vaks_doperw.jpg?anchor=center&mode=crop&quality=65&width=152&height=152&rnd=130362644350000000" alt="3Vaks Doperw" /><div class="caption"></div></a></li><li class="row3 column3 nr9"><a href="#" target="_blank"><img src="/media/9659/slagroomtaart.jpg?anchor=center&mode=crop&quality=65&width=152&height=152&rnd=130362644610000000" alt="Slagroomtaart" /><div class="caption"></div></a></li><li class="row1 column1 nr10"><a href="#" target="_blank"><img src="/media/9657/schuddenbeukjes.jpg?anchor=center&mode=crop&quality=65&width=152&height=152&rnd=130362644590000000" alt="Schuddenbeukjes" /><div class="caption"></div></a></li><li class="row1 column2 nr11"><a href="#" target="_blank"><img src="/media/9638/frambozen_vanille_yoghurt.jpg?anchor=center&mode=crop&quality=65&width=152&height=152&rnd=130362644460000000" alt="Frambozen Vanille Yoghurt" /><div class="caption"></div></a></li><li class="row1 column3 nr12"><a href="#" target="_blank"><img src="/media/11450/glorix.jpg?anchor=center&mode=crop&quality=65&width=152&height=152&rnd=130396236310000000" alt="Glorix" /><div class="caption"></div></a></li><li class="row2 column1 nr13"><a href="#" target="_blank"><img src="/media/11458/stoffer_blik.jpg?anchor=center&mode=crop&quality=65&width=152&height=152&rnd=130396236350000000" alt="Stoffer Blik" /><div class="caption"></div></a></li><li class="row2 column2 nr14"><a href="#" target="_blank"><img src="/media/11448/biedemeijer.jpg?anchor=center&mode=crop&quality=65&width=152&height=152&rnd=130450541530000000" alt="Biedemeijer" /><div class="caption"></div></a></li><li class="row2 column3 nr15"><a href="#" target="_blank"><img src="/media/9631/bolletje_beschuit.jpg?anchor=center&mode=crop&quality=65&width=152&height=152&rnd=130362644410000000" alt="Bolletje Beschuit" /><div class="caption"></div></a></li><li class="row3 column1 nr16"><a href="#" target="_blank"><img src="/media/9637/frambozen.jpg?anchor=center&mode=crop&quality=65&width=152&height=152&rnd=130362644450000000" alt="Frambozen" /><div class="caption"></div></a></li><li class="row3 column2 nr17"><a href="#" target="_blank"><img src="/media/11455/paaseendje.jpg?anchor=center&mode=crop&quality=65&width=152&height=152&rnd=130396236330000000" alt="Paaseendje" /><div class="caption"></div></a></li><li class="row3 column3 nr18"><a href="#" target="_blank"><img src="/media/9640/gamba.jpg?anchor=center&mode=crop&quality=65&width=152&height=152&rnd=130362644470000000" alt="Gamba" /><div class="caption"></div></a></li><li class="row1 column1 nr19"><a href="#" target="_blank"><img src="/media/9652/oranje-bitter.jpg?anchor=center&mode=crop&quality=65&width=152&height=152&rnd=130362644550000000" alt="Oranje Bitter" /><div class="caption"></div></a></li><li class="row1 column2 nr20"><a href="#" target="_blank"><img src="/media/9625/ananas.jpg?anchor=center&mode=crop&quality=65&width=152&height=152&rnd=130362644370000000" alt="Ananas" /><div class="caption"></div></a></li><li class="row1 column3 nr21"><a href="#" target="_blank"><img src="/media/11456/paaseitjes.jpg?anchor=center&mode=crop&quality=65&width=152&height=152&rnd=130396236340000000" alt="Paaseitjes" /><div class="caption"></div></a></li><li class="row2 column1 nr22"><a href="#" target="_blank"><img src="/media/9624/abrikozen.jpg?anchor=center&mode=crop&quality=65&width=152&height=152&rnd=130362644360000000" alt="Abrikozen" /><div class="caption"></div></a></li><li class="row2 column2 nr23"><a href="#" target="_blank"><img src="/media/9623/3vaks_tuinbonen.jpg?anchor=center&mode=crop&quality=65&width=152&height=152&rnd=130362644350000000" alt="3Vaks Tuinbonen" /><div class="caption"></div></a></li><li class="row2 column3 nr24"><a href="#" target="_blank"><img src="/media/11459/zeem.JPG?anchor=center&mode=crop&quality=65&width=152&height=152&rnd=130396236360000000" alt="Zeem" /><div class="caption"></div></a></li><li class="row3 column1 nr25"><a href="#" target="_blank"><img src="/media/9655/radijs.jpg?anchor=center&mode=crop&quality=65&width=152&height=152&rnd=130362644580000000" alt="Radijs" /><div class="caption"></div></a></li><li class="row3 column2 nr26"><a href="#" target="_blank"><img src="/media/9627/asperges.jpg?anchor=center&mode=crop&quality=65&width=152&height=152&rnd=130362644390000000" alt="Asperges" /><div class="caption"></div></a></li><li class="row3 column3 nr27"><a href="#" target="_blank"><img src="/media/9656/sandwichspread.jpg?anchor=center&mode=crop&quality=65&width=152&height=152&rnd=130362644580000000" alt="Sandwichspread" /><div class="caption"></div></a></li><li class="row1 column1 nr28"><a href="#" target="_blank"><img src="/media/9650/mais.jpg?anchor=center&mode=crop&quality=65&width=152&height=152&rnd=130362644540000000" alt="Mais" /><div class="caption"></div></a></li><li class="row1 column2 nr29"><a href="#" target="_blank"><img src="/media/9666/wasverzachter.jpg?anchor=center&mode=crop&quality=65&width=152&height=152&rnd=130450541530000000" alt="Wasverzachter" /><div class="caption"></div></a></li><li class="row1 column3 nr30"><a href="#" target="_blank"><img src="/media/9633/brood.jpg?anchor=center&mode=crop&quality=65&width=152&height=152&rnd=130362644420000000" alt="Brood" /><div class="caption"></div></a></li>    </ul>
    

    update: reviewing my code, it's proberly the html.raw

  • Wesley de Roo 38 posts 142 karma points
    May 20, 2014 @ 16:54
    Wesley de Roo
    0

    Html.Raw was the problem. Thnx for helping...

  • Jeavon Leopold 3074 posts 13632 karma points MVP 11x admin c-trib
    May 20, 2014 @ 16:57
    Jeavon Leopold
    0

    Yes, that is exactly it. You could encode it yourself, e.g. HttpUtility.HtmlEncode(img.GetPropertyValue("productnaam"))

  • Jeavon Leopold 3074 posts 13632 karma points MVP 11x admin c-trib
    May 20, 2014 @ 16:58
    Jeavon Leopold
    0

    Edit, that should have been HttpUtility.UrlEncode(img.GetPropertyValue("productnaam"))

  • Wesley de Roo 38 posts 142 karma points
    May 20, 2014 @ 17:13
    Wesley de Roo
    0

    It was HttpUtility.HtmlEncode.

    HttpUtility.UrlEncode in combination with Html.Raw gives me:

    <img src="%2fmedia%2f9635%2fde_ruijter_vruchtenhagel.jpg%3fanchor%3dcenter%26mode%3dcrop%26quality%3d65%26width%3d152%26height%3d152%26rnd%3d130362644440000000" alt="De Ruijter Vruchtenhagel">
    

    Thnx. Again :)

  • Jeavon Leopold 3074 posts 13632 karma points MVP 11x admin c-trib
    May 20, 2014 @ 17:20
    Jeavon Leopold
    100

    Great, it was HttpUtility.HtmlEncode, right?

  • Jeavon Leopold 3074 posts 13632 karma points MVP 11x admin c-trib
    May 20, 2014 @ 17:51
    Jeavon Leopold
    0

    I would really try and get rid of that Html.Raw, it shouldn't be needed like that....?

  • Wesley de Roo 38 posts 142 karma points
    May 20, 2014 @ 19:18
    Wesley de Roo
    0

    Yeah, i should. It has a lot of old code in it from my early days :)

Please Sign in or register to post replies

Write your reply to:

Draft