4 Replies Latest reply on Aug 8, 2007 9:31 AM by cf_dev2

    Two problems

    jdyerjdyer
      My first problem might be the easier of the two. I have this function that accepts two named arguments and 3 additional unnamed ones. Depending on the value of the 4th argument (True or False) if passed in, the 5th argument is used.
      My problem is, it seems to me that if the 4th argument is passed in as False, CF quits reading the arguments. I checked the length of Arguments array in the function and it always reads 4 (including the False) but ignores everything past this value.
      Is this supposed to happen?
      //Searches for tagname in str with attributes in array attarr.
      //Returns start tag only if startOnly is True.
      //If startOnly is False, and innerHTML is passed in, checks to see if the content between start tag and end tag matches this.
      function getTag(str,tagname) //attarr,startOnly,innerHTML
      {
      }
      //function call, page holds an html page I retrieved already, attarr is defined ArrayNew(2) earlier
      attarr[1][1]="name";
      attarr[1][2]="myForm";
      form = getTag(page,"form",attarr);//This works and finds the form.
      attarr[1][1]="name";
      attarr[1][2]="error";
      form = getTag(form,"label",attarr,False,"That name is already used."); //This fails, function says only 4 arguments passed in.


      Second problem is insane. (imagine pulling hair out in clumps, red eyed, holding half empty energy drink)
      500 Null, ooopps, the dreaded.
      It always occurs when I'm using a regular expression that isn't 100% greedy. Let me give an example.
      Here is a basic re to match html tags.
      Notice the * after [^<]. This is the greedy form that works.
      <#tagname#[^>]*>(([^<]*|[<](?!/#tagname#>))*)</#tagname#>
      I want to know why I can't leave this greediness out, and have it match the zero or more subexpressions instead, but more importantly, I want to know how I can get CF to turn its head and cough.
      I mean, how am I supposed to find out what is going wrong when it just displays 500 Null.
      I did the comment dance and narrowed it down to this part of the re
      ([^<]|[<](?!/#tagname#))*
      To me this reads, give me a character that is not < or give me one that is < as long as /#tagname# doesn't follow.
      Now give me zero or more of these characters.
      Am I wrong here? And is there a way to catch 500 Nulls at all? Just in case there is a problem in one of my re's that doesn't pop up in testing, but shows up in production. I want to shut the page down softly. Not abruptly. I appreciate the help.
      Sorry for being long winded, but I've spent three days on these errors without any luck.
        • 1. Re: Two problems
          jdyerjdyer Level 1
          Can anyone help me?
          • 2. Re: Two problems
            cf_dev2 Level 1
            Just to get the ball rolling, can you post more specifics about the function? I tried a simple test and the argument length is 5, not 4. Also, have you tried using cffunction / cfargument instead?

            • 3. Two problems
              jdyerjdyer Level 1
              I call this function but the arraylen(arguments) gt 4) part never executes. (Correction, it executes, but value is then overwritten!!!)
              This function uses the hastag function to search and then strips the tag found out.
              Makes it easy to loop through the file and process each of the tags I am looking for, one at a time.

              >>>OMG>>> I just realized, when I added the 5th argument to this one, I forgot to change the if to else if, so after processing once it processes this one also!!! Sorry, about that. Any help with the RE problem and 500 Null?

              function removeTag(str, tagname)
              {
              var tag = "";
              if(ArrayLen(arguments) gt 4)
              {
              tag=hasTag(str,tagname,arguments[3],arguments[4],arguments[5]);
              }
              if (ArrayLen(arguments) gt 3)
              {
              tag = hasTag(str,tagname,arguments[3],arguments[4]);
              }
              else if (ArrayLen(arguments) gt 2)
              {
              tag = hasTag(str,tagname,arguments[3]);
              }
              else
              {
              tag = hasTag(str,tagname);
              }
              if (len(tag) GT 0)
              {
              return REReplace(str,tag,"","ONE");
              }
              else
              {
              return "";
              }
              }
              • 4. Re: Two problems
                cf_dev2 Level 1
                I don't know about the 500 null error. I would check the logs to see what information they contain about the error. Stupid question but have you tried catching the error (ie cftry/cfcatch or try/catch)?