- Image via Wikipedia
Late last week I was working on some new changes to PBR’s web site (my employer) and ran into a nasty snag of an issue. I was pulling data out of a table, and for an exceptionally strange reason, seemingly random HTML kept appearing in the source code. Needless to say, this HTML was breaking the layout I had been working towards and boggled not only my mind, but our SVP of IT’s mind as well.
In the end, we ended up changing the field type as it was held in the Microsoft SQL database. The field was originally set to be an ntext field, and we changed it to a varchar field, as it really had no purpose being an ntext field in the first place, but that’s another story. After we made the change, we did lose some data on the resulting trimming of the data field, however the parts that were trimmed were already migrated to another field, so big loss.
As soon as we changed this, the HTML injections ceased. What happened? I have put some sample code below to illustrate it.
What the code should have came out to be.
<div id="myDiv">
<p class="indentClass">
My content was coming out of the db here
</p>
</div>
What the code actually came out to be before we changed the field type.
Quick Code
<div id="myDiv">
<p class="indentClass">
</p>
<p>My content out of the db here</p>
<p></p>
</div>
You can see that my opening paragraph tag was automatically closed, a new one started and closed after the database content was published, and an empty paragraph added at the end.
Now it is possible that the site, with the many thousands of pages and hundreds of thousands of lines of code specified this in a CFC or CFTAG file – in other words it was tied to the field name/type to force the HTML output, but I could not find it anywhere.
Any thoughts or experience you may have on this? Share them in the comments.
![Reblog this post [with Zemanta]](http://img.zemanta.com/reblog_e.png?x-id=2b743204-6f88-437c-93b6-f50353ea70ab)
![Reblog this post [with Zemanta]](http://img.zemanta.com/reblog_e.png?x-id=40cc0202-836c-4026-bbd0-06236d0397f1)

