Missing space character in output HTML

Topics: Core, Troubleshooting
Nov 9, 2011 at 2:58 PM

Hi there, I'm having a very peculiair, hard to reproduce issue. It sometimes happens that the HTML output of a page is missing one or two spaces. Like this screenshot, there's no space between <li and the class attribute...

It happened about two times, both times in a partial that I'm rendering in a driver-based CSHTML file. One of those times I figured out that if I added spaces or enters in the line above or below the one that faulted, it fixed the problem. But what the problem exactly is... no clue. Even less on how to fix it.

Has anyone seen anything similar? Where can I start looking? Could it be Orchard or even a Razor issue? Thanks in advance!

Nov 9, 2011 at 3:22 PM

Can you post your .cshtml code to check it's not something obvious?

Saying that, I had a really odd error like this at one point where a single character was getting dropped from HTML output for absolutely no good reason. I can't now remember the specific circumstance but it was truly baffling.

Nov 9, 2011 at 3:48 PM
Edited Nov 10, 2011 at 10:05 AM

Alright, I've got a way to reproduce this issue: using IIS SEO Toolkit. For some reason, when I run it, a lot of pages have this same problem.

You asked for it: the (simplified) CSHTML file

<tbody>
  @foreach (var row in Model.PriceTableNightsView)
  {
  <tr>
    <td class="nights">
    @foreach (var cell in table)
    {
        <td class="@className" data-price="@Utils.Money(cell.FromPrice, true, false)" 
        rel="@cell.DateOfArrival.ToString("yyyyMMdd")">
          <div>
            <a href="">@Utils.Money(cell.FromPrice, false, false)</a>
          </div>
        </td>
    }
    <td class="last">&#160;</td>
  </tr>
  }
</tbody>

The output HTML

<tr id="37"  class="hidden" >
  <td class="nights" data-nights="37">37 &nbsp;nachten</td>
      <td class="price" data-price="2035,00" 
      rel="20120101">
        <div>
          <a href=""  >2035</a>
        </div>
      </td>
      <td class="price" data-price="2035,00" 
      rel="20120102">
        <div>
          <a href=""  >2035</a>
        </div>
      </td>
      <td class="price" data-price="2035,00" 
      rel="20120103">
        <div>
          <a href=""  >2035</a>
        </div>
      </td>
      <td class="price" data-price="2035,00" 
      rel="20120104">
        <div>
          <a href=""  >2035</a>
        </div>
      </td>
      <td class="price" data-price="2035,00" 
      rel="20120105">
        <div>
          <a href=""  >2035</a>
        </div>
      </td>
      <td class="price" data-price="2035,00" 
      rel="20120106">
        <div>
          <a href=""  >2035</a>
        </div>
      </td>
      <td class="price" data-price="2035,00"rel="20120107">
        <div>
          <a href=""  >2035</a>
        </div>
      </td>
  <td class="last">&#160;</td>
</tr>

As you can see, the "truly baffling" thing is that it only occurs on one of the iterated items! How bizar is that?!

When I direct my browser to the same URL it gets served the HTML like you would expect. But when the "Search Engine Optimization" module of IIS executes the same URL it has 2 of these issues.

Nov 9, 2011 at 4:01 PM

The reason I suspect Orchard of being involved is that there's a module (OfficineK.HTMLToolkit) that makes it possible to compress the output HTML.
So there is some kind of pipeline-stuff going on. But here's the thing, when I turn on output html compression, I get the same issue:

...<td class="price" data-price="2035,00"rel="20120107"><div><a href="" >...

Owh, and it doesn't occur when I request only one page with IIS SEO toolkit, but it does when I set it to request 5 pages. If you can shed any light, it'd be really appreciated!

Nov 9, 2011 at 4:08 PM

I'm wracking my brains trying to remember where I had this similar problem. I remember digging into MVC source code to see if some obscure combination of characters was triggering the problem. But I can't for the life of me remember exactly what it was (and I've been looking back through my repos to find the relevant commit, unfortunately nothing stood out).

It sounds like there's a conflict in the way various parts of IIS and Orchard are interacting, but it's incredibly hard to tell. Have you installed all the latest software updates? ... Is this on a live or development machine?

Nov 9, 2011 at 4:38 PM

I've seen it on two different development machines (a vista-32bit and a win7-64bit), and now the customer experienced the same issue on its test environment. I don't know the specs of that machine.

I'm trying to trace where it goes wrong. The ShapeTemplateBindingStrategy.Render function gets the valid HTML, so it goes wrong somewhere later on in the process... 
My day is done, i'm continuing the search tomorrow... 

Nov 10, 2011 at 10:21 AM
FOUND IT!
argh, this took me quite some time. But the problem was in the OfficineK.HTMLToolkit module that's a little too greedy, even if you 
don't want it to compress anything.
The full explanation is on http://developer.3l.nl/post/12594777614/output-missing-a-space-character.
I also notified the developers at OfficineK.
Thanks for bearing with me, @randompete!