1

My program has a bug -- the output has extra junk in it that doesn't belong there. Firebug shows me lines of code that would produce exactly this unwanted junk, but I don't have those lines in my program. I have spent hours on this and cannot solve it. Here is what Firebug says I have (the stuff in wavy brackets are my comments:

<tr>
<td class="repnum" style="width: 20px">1 </td>                {td 1}
<td class="reprow" style="text-align: left; "> Maura</td>     {td 2}
<td class="reprow" style="text-align: left; "> Cronin</td>    {td 3}
<td class="repsort subhead"> </td>                   cannot find this anywhere 
</tr>
<tr>                                                 cannot find this anywhere
<td class="repsort2 subhead "> </td>                 cannot find this anywhere
</tr>                                                cannot find this anywhere

Part of my program below. The actual program has other ColdFusion stuff in it, but no additional HTML.

 <tr>
   ... other stuff ...
 <cfloop from = "#subpage1#" to = "#subhind_1#" index = "j"> 
 <cfif sortnum[j] EQ 'y'>
   <cfif subhdup[j][row] EQ "NO">
   <cfset ctr[j] = 1>
   <cfelseif subhdup[j][row] EQ "YES">
   <cfset ctr[j] = ctr[j] + 1> <cfloop from = "#subpage1#" to = "#subhind_1#" index = "j"> 
   <cfif sortnum[j] EQ 'y'>
   <cfif subhdup[j][row] EQ "NO">
   <cfset ctr[j] = 1>
   <cfelseif subhdup[j][row] EQ "YES">
   <cfset ctr[j] = ctr[j] + 1>
   </cfif>

   <td class = "repnum" style = "width: 20px">#ctr[j]# </td>  td 1
 </cfif>
 </cfloop>


<cfloop from = "#subhind#" to = "#bbcollen#" index = "j">
<cfset col = bbcol[j]>

 <cfset i = i + 1>
       <cfif linefold GT 0>
       <cfset imod = i%linefold>
       <cfelse>
       <cfset imod = 1>
       </cfif>

       <cfif linefold EQ 0 OR (linefold GT 0 AND i LE linefold)> 
       <cfset lineclass = "reprow">
       <cfelse>
       <cfset lineclass = "reprow2">
       </cfif> 

      <cfif repdetail NEQ 'n'>     
      <cfoutput>
      <cfset jcol = inpcol[j]>
      <cfset temp    = structaux["#jcol#InputType"]> 

      <cfif temp EQ "num" OR temp EQ "one"> 
        <cfset anumform = NumberFormat(qrep[col][currentrow],.99)>
           <td class = "#lineclass#" style = "text-align: right"> #anumform#</td> 
      <cfelseif temp EQ "date">
           <cfset adate = DateFormat(qrep[col][currentrow],'mm/dd/yyyy')>
              <cfif adate EQ "01/01/1001">
              <cfset adate = "~">
              </cfif>
           <td class = "#lineclass#" style = "text-align: left"> #adate#</td> 
      <cfelse>
            <td class = "#lineclass#" style = "text-align: left; "> #qrep[col][row]#</td>

      </cfif><!---temp eq num --->

</cfloop> <!---subhind to bbcollen --->  
  ... other stuff ...
</tr>

Does anyone have a suggestion?


as per request I had expanded the code presented

Someone said that this is about whitespace. It is not. If it were whitespace I'd be okay. But I've got all sorts of css dropping into those extra spaces, creating borders etc. It really produces an illegible mess.

Betty Mock
  • 1,373
  • 11
  • 23
  • Do you all of your tags need to be closed? – BuddhistBeast Dec 27 '13 at 04:08
  • If they are not ColdFusion throws a fit; so they are. – Betty Mock Dec 27 '13 at 05:57
  • Not all of the above are closed, at least that is what it seems. – BuddhistBeast Dec 27 '13 at 06:01
  • My suggestion is to comment out all the code between your opening and closing html tags and run the page. View the html source code produced by your browser. If it contains stuff you didn't put there, you have probably been hacked. Otherwise, uncomment your code bit by bit and run the page until the problem recurs. The last piece of code you uncommented will be the cause. – Dan Bracuk Dec 27 '13 at 13:15
  • you're missing at least 2 closing `cfif` tags in your posted example. Please post your actual code that is running on the page. – Matt Busche Dec 27 '13 at 13:52
  • The posted code also has nested `cfloops` using the same index variable name `j`. That's a recipe for headaches, doubly so since inner one is missing its closing tag – Joe C Dec 27 '13 at 14:15
  • If I were looking for the code in question, my guess is that it would reside under the second `... other stuff ...` – Avery Martell Dec 27 '13 at 16:16
  • @phantom42 Hi, the loops are not nested -- each of them is closed before starting the next one. Perhaps that doesn't show in the code I submitted. Sorry. – Betty Mock Dec 27 '13 at 20:28
  • @MattBusche Yes Matt -- they are there, but many, many lines farther down the page. You can't leave out closing ifs or ColdFusion will halt everything until you fix it. – Betty Mock Dec 27 '13 at 20:30
  • @DanBracuk The problem with commenting out code in ColdFusion is that it grinds to halt if you comment out something it needs later. You can't even get – Betty Mock Dec 27 '13 at 20:32
  • To all who are trying to help -- would it be useful if I give a link to the entire several hundred lines that are causing trouble? I can post them somewhere. – Betty Mock Dec 27 '13 at 20:33
  • Since I'm not smart enough to work with 2000 lines of code in a single file, when I need that much code, I make smaller files and cfinclude them from a master. One benefit of such an approach is that you can simply comment out cfinclude tags when faced with situations like this. – Dan Bracuk Dec 27 '13 at 20:44
  • @DanBracuk the 2000 lines is in 9 included modules plus a master program that calls them. Commenting one out would interrupt the entire thing and the program would not proceed. – Betty Mock Dec 27 '13 at 23:51
  • To everyone who tried to help -- I found the problem. To do so I removed most of the program, leaving about 20 lines; the error was still there. There were two problems actually. One wasn't even visible in that module. I had set the between my lines -- generated by one of the loops. I had checked the loop start and end points very carefully, but it slipped in anyway.
    – Betty Mock Dec 27 '13 at 23:55
  • Thank you all for helping. Just knowing I can write to Stack Overflow helps keep the frustration under control. – Betty Mock Dec 27 '13 at 23:56

4 Answers4

1

I think this Stack question can better answer why there is random html output. It could also be the browser trying to correct all of the incorrect HTML that is possibly in your code.. in other words, you might have a small error such as your tags are not matched together.. either way, the browser is catching the errors and still producing the exact code that you want. With that being said, it really isn't anything to fret over unless you want to overlook your code and find exactly where the tags may not be matching up.

As I have extremely limited knowledge on ColdFusion, I would suggest a Syntax Checker that another Stack question has gone over. After finding if your syntax is correct or not, this may highlight the exact area that needs to be worked on.

Community
  • 1
  • 1
BuddhistBeast
  • 2,652
  • 2
  • 21
  • 29
1

ColdFusion will not generate <tr> or <td> unless the code says so.

Normally extra white space is not significant and will not alter what is shown on the browser.

If you do have a region that must not have space, add it <cfsilent> make to remove space generation.

James A Mohler
  • 11,060
  • 15
  • 46
  • 72
  • 1
    Well, it came from somewhere, didn't it? This is not a white space problem. Not at all. The extra code is dropping unwanted css formatting into those spaces. – Betty Mock Dec 27 '13 at 05:58
  • 6
    Yeah, but what James is saying is that it's not *ColdFusion* doing it. You need to stop positioning this in your mind as "ColdFusion doing this" and position it as "something in your code somewhere is doing it, and you just don't understand why". ColdFusion does not write out code fragments of its own accord; it will simply be running some code you have asked it to, and you are not understanding why that's happening. Search your code base for "repsort2": that'll identify where the code is, then you gotta work out why it's being called. – Adam Cameron Dec 27 '13 at 09:08
  • 1
    I agree with James, ColdFusion doesn't add html code it's not asked to add. – Avery Martell Dec 27 '13 at 16:14
  • @AdamCameron You are quite right -- I was generating the code myself, due to omitting a condition that was needed to avoid generating it. I found the bad line very quickly, because there is only one repsort2 in the code; and I verified that was where the problem was. And it still took me over 24 hours to figure out what was wrong. – Betty Mock Jan 01 '14 at 08:48
  • @AdamCameron Re not generating code fragments, it appears that it does indeed do so. The trivial example is that something adds a tbody tag whether I have one or not. It also generates /tr tags that might be left out. Additionally I have run into numerous bugs in ColdFusion, which I have had to work around. So it is not obvious to me when my problem is me or something weird or unexpected in the implementation of the product. – Betty Mock Jan 01 '14 at 08:54
  • 1
    Betty, the `tbody` / `tr` stuff is the browser's DOM engine "fixing" bad mark-up. The DOM can only work with a syntactically valid document, so if it doesn't receive one, it has to make a best stab at how to make it valid. ColdFusion is completely unaware of the concept of "mark-up" (other than tags that spit some out, like ``, `` etc), so it will not be outputting random remedial mark-up like that. When you are in situations like this, it will either be your code doing it, or the DOM trying to repair invalid mark-up you've generated. Either way: from *your* code. – Adam Cameron Jan 01 '14 at 10:00
  • 1
    I stress this because when faced with issues like the above, you need to start out from the position that it's not CF doing any of this, it will be *your code* doing. So that's where you need to focus. Not on being bemused about CF (or anything else) performing what seems to be magic. There is no such thing as magic. So dispense with the notion you are victim of magic, and just starting looking for where the bugs in your own code are. – Adam Cameron Jan 01 '14 at 10:02
0

Make sure you are really looking at the correct block of code. The reason I say that is because your CF logic has spaces on either side of the equal sign for the class attribute but the rendered HTML doesn't (I'm not sure if you modified it or not). I use CF daily and have never seen this. When viewing source the browser will add html from time to time like <thead> and <tbody> tags but nothing like in your example. I'd say (1) make sure you are looking at the correct block of code (2) show more of your page so we can follow the process, for instance, what is setting #lineclass#. Just follow the logic, add some cfdumps, or post the full page so we can help more.

gfrobenius
  • 3,987
  • 8
  • 34
  • 66
  • I do seem to be looking at the right code. When I change it the changes are reflected in the right place. And the extra code is packed around the correct code. I will search the later parts of the program to see if there is anything there; and thank you for that suggestion. If I can't get anywhere, I'll post more code. The entire "program" consists of about 2000 lines, broken into several modules which are used elsewhere. So it's a bit much to try to read. However, I'll post the #lineclass# code now. – Betty Mock Dec 27 '13 at 05:47
  • I think its your if conditions. I know you didn't post all the code because of its length but something is setting lineclass to "report subhead" and "repsort2 subhead" but I don't see those strings in your code. I would search your code for those strings. They could be separate from one another, it could set lineclass to "repsort2" then later in the code append the " subhead" so you may want to search for those strings individually. Once you find those strings work your way back from there by dumping out loop indexes and other vars to figure out where your loop or if conditions are incorrect. – gfrobenius Dec 27 '13 at 08:15
  • So when find "repsort2" in the code, if its anything like your example above, you could do something like this: then when you view source use that info to debug your if conditions/loops. – gfrobenius Dec 27 '13 at 08:20
  • -- it is impossible to put unbalanced if's into ColdFusion; it throws an immediate error. Lineclass is not producing repsort and repsort2, which are hard-coded in, as is "subhead". I added the lineclass code to my question, so people could see that. – Betty Mock Jan 01 '14 at 08:59
0

I would be willing to bet your a 1974 Ford Pinto that if you do an extended text search on all of the code in your project, all of the file types, you will find the code that you're considering extra.

  • I did find where I was generating extra code -- I needed another condition before starting one of the loops. However, I would like to know how to do an extended text search -- I've needed to be able to do that, but didn't know there is a way. – Betty Mock Jan 01 '14 at 08:43
  • If I had a 1974 Ford Pinto I would give it to you. – Betty Mock Jan 01 '14 at 08:57
  • @everyone -- I am impressed and grateful that so many of you were willing to put in time to help me out. I can't remember when I last spent so much time on a bug; it was very frustrating. And yes, it was my error. – Betty Mock Jan 01 '14 at 09:02