views:

142

answers:

3

I'm having a very strange output corruption on one of my PHP sites. Sometimes, a piece of HTML code is displayed, rather than the tags being interpreted. It looks like some characters are missing, messing up the tags. See the example below: the second line should just be a link to c1, but due to some reason part of the target URL is shown.

alt text

The problem is temporary, a refresh usually solves it. This can happen on different parts of the page (although often in the same location). Only Safari seems affected (but I'm suspecting Firefox just masks the problem due to more tolerant parsing). It happens on both my development server as the live one, they both have slightly different settings (output buffering, chunked transfer), although the probability of it happening seems to vary.

Anyone ever seen something like this??

EDIT

When I "View Source" in Safari on this page, I get the following HTML:

<tr class="odd">
  <td>73</td>
  <td><a href="companies.php?view=1&amp;companyid=73&amp;return=%2Foffice%2Fcompanies.php">c1</a></td>
  <td></td>
  <td><img src='/images/dot_blue.png'  class="altTooltip" alt="inactive: no account"  /> </td>

I can't see anything wrong with this, so either Safari has reloaded the page when I asked it for the source, or I'm not looking hard enough...

+2  A: 

Well, here's my shot in the dark.

The break occurs in the word "office", after the fi character combination. I would bet that the fi ligature is -- somehow -- causing trouble.

How exactly? Since that HTML code doesn't contain the ligature character, this might be a bug in Safari. Especially since it occurs randomly. Could you try to rename that file, and see if the problem goes away?

Having valid HTML might also help in avoiding this problem, because it makes parsing easier.

Thomas
That's a very clever thought, but it looks like it's part of a URL. I can hardly imagine there really being a `fi` in there.
Pekka
Unless it's a bug, and part of the parser treats it as visible text. Then a fi -> fi replacement might make sense.
Thomas
I was also thinking towards a Safari rendering bug. Downloading and comparing the file hundreds of times didn't cause any changes, nor was there anything wrong with the page content when I stored it at the server. Moreover, as you can see in the screenshot, the 3 icons at the right are above each other. After a refresh they are next to each other. In both IE and FF I've never seen them rendered vertically.
Wim
I think the vertical positioning is down to the HTML being broken (unclosed tags) - pay them no heed. I find it hard to believe in a rendering bug here, it feels like the data gets garbled somehow - why only in Safari, I don't know. Thomas's `fi` idea is far-fetched but still makes the most sense. What kind of server environment is this? Are there any reverse proxies or something?
Pekka
Also, have you tried this on various client computers? This could as well be a firewall / antivirus program on your end.
Pekka
Web Inspector to the rescue: TinyMCE has inserted his `<script>` tags inside my own HTML!
Wim
+1  A: 

When you select a piece of HTML and view source, what you get is not 100% what is there. For instance, all of you &'s are &amp;, which probably means you selected the offending text and viewed the selection's source.

If you are still having the issue, trying viewing the whole source code without selecting anything, and then using ctrl + f to find the spot in the code, and try and give us a larger sample, not just the offending row, but a correct row, and in a larger context.

For instance, when using tables, a mislaid <td> can have very weird consequences, this doesn't look like that type of issue, I am just saying that we need context to be able to help.

There's also the issue that some browsers, in order to view source, actually resubmit the page and get a second copy of it. I have a feeling that it is the code that's outputting the text, so look and see if you are using something like

<?= $someVar ?>

and make sure it's not like this:

<a href=<?= isset($x) ?'"'. $someVar.'"': '"'.$someOlderVar.'">'?>> xxx </a>

So, no selecty, and bigger sample please. And we'd prolly need something from the code that outputs the errored HTML...

Bart van Heukelom
You misunderstand, you don't escape HTML Entities in urls, i.e. the ampersand is a valid symbol for urls, it shouldn't be replace by the html entity version, your urls will behave oddly when you do that.
R. Bemrose
+1  A: 

I finally found the problem (using Web Inspector): TinyMCE has been inserting tags (which it uses to load language files and extension modules), at seemingly random places inside my own HTML. The result was that, in the case visible from my screenshot, something like <a href="foo<script src="tinymce/lang/en.js">bar.php">foobar</a>.

Since I'm also using jQuery on the same page, my guess is it was ultimately cause by jQuery's modifications to the DOM and TinyMCE's additions happening at the same time which resulted in some sort of race condition (caused by a bug that only appears to exhibit itself in Safari).

I am now using the jQuery build of TinyMCE, and all has been well since...

Thanks to everyone for the help!

Wim