AI Zone Admin Forum Add your forum

NEWS: Chatbots.org survey on 3000 US and UK consumers shows it is time for chatbot integration in customer service!read more..

bug with using temp variable as index for json arrays
 
 

Bruce,

The following code works fine on windows chatscript.exe from 4/2/2018

$$_curItem 0
    
^loop( $$_result.responseHeader.params.rows ){
     
$$_href = ^join\" https://www.bcbsal.org/web/provider-finder $$_result.response.docs[$$_curItem].uniqueURL \" )
     
\n <a  target="_blank"> $$_result.response.docs[$$_curItem].fullname </aof $$_result.response.docs[$$_curItem].dbasname[0]
     
$$_curItem += 1
    } 

it returns:

include: \r\n<a href "https://www.bcbsal.org/web/provider-finder#/details/98491941/56460511//GeneralDentistry/JamesAultmanDMD" target=" blank"JAMES AULTMAN </aof Aultman Dental LLC\r\n<a href "https://www.bcbsal.org/web/provider-finder#/details/98382929/70994511//GeneralDentistry/JordinBarkleyDMD" target=" blank"JORDIN BARKLEY </aof Pediatric Dental Associates Of Birm\r\n<a href "https://www.bcbsal.org/web/provider-finder#/details/51091487/40020510//GeneralDentistry/ScottBarnettDMD" target=" blank"SCOTT BARNETT </aof PELL CITY DENTAL CENTER PC\r\n<a href "https://www.bcbsal.org/web/provider-finder#/details/98162794/11053510//Orthodontics/TMichaelBrooksDMD" target=" blank"T.MICHAEL BROOKS </aof ST CLAIR ORTHODONTICS\r\n<a href "https://www.bcbsal.org/web/provider-finder#/details/98024575/46632515//Pedodontics/BakerChamblissDMD" target=" blank"BAKER CHAMBLISS </aof PEDIATRIC DENTAL ASSOCIATES LLC\r\n<a href "https://www.bcbsal.org/web/provider-finder#/details/98082981/4630510//GeneralDentistry/AndreaCibulskiDMD" target=" blank"ANDREA CIBULSKI </aof Eden Family Dentistry Inc \r\nwould you like to


However with the latest version of Chatscript it returns:

they include: \r\n<a href "https://www.bcbsal.org/web/provider-findercs[$$_curItemtarget=" blank"ocs[$$_curItem\r\n<a href "https://www.bcbsal.org/web/provider-findercs[$$_curItemtarget=" blank"ocs[$$_curItem\r\n<a href "https://www.bcbsal.org/web/provider-findercs[$$_curItemtarget=" blank"ocs[$$_curItem\r\n<a href "https://www.bcbsal.org/web/provider-findercs[$$_curItemtarget=" blank"ocs[$$_curItem\r\n<a href "https://www.bcbsal.org/web/provider-findercs[$$_curItemtarget=" blank"ocs[$$_curItem\r\n<a href "https://www.bcbsal.org/web/provider-findercs[$$_curItemtarget=" blank"ocs[$$_curItem \r\nwould you like to

 

 

 
  [ # 1 ]

I’ll need to replicate some example. Can you email me code that has the $$result data in it so I can see what happens?

 

 
  [ # 2 ]

Bruce,

Had to prep for a big demo, but now I can get back to this. I tried the following code, thinking that it would duplicate the problem, but it does not. However, the problem does exist as you can see in my initial post. Do you have a suggestion on what could be causing the issue? Obviously, my initial diagnosis is incorrect. Now I need help figuring out why one version of chatscript prints my information and the newest one prints part of the code.

here is the code that I thought would duplicate the problem but it does not.

##<<
demonstration of bug using volley only local variables as the index to a json array
##>>

topic: ~bug-tests-topic keep repeat (run bug tests)


#! one
uLOCAL_VARIABLE_ARRAY_INDEX one )

 
testing local variable array index potential bug
 
^flushoutput()

  $
$_jsonstring = ^'
  {
    "version": 23,
    "rows": [
      {
        "row": "zero",
        "info": "row 0 info"
      },
      {
        "row": "one",
        "info": "row 1 info"
      },
      {
        "row": "two",
        "info": "row 2 info"
      },
      {
        "row": "three",
        "info": "row 3 info"
      }

    ]
  }
  '
 
   
$$_json = ^jsonparse($$_jsonstring)
   ^
jsontree($$_json)
   $
$_thisItem 0
   
$$_rgSize = ^length($$_json.rows
   ^
loop( $$_rgSize){
    \n looping 
    
$$_href = ^joinrow $$_thisItem ": " \" $$_json.rows[$$_thisItem].info \" )
    $
$_href
    
$$_thisItem += 1
   } 
 

 
  [ # 3 ]

Here is code that duplicates the problem.

##<<
demonstration of bug using volley only local variables as the index to a json array
##>>

topic: ~bug-tests-topic keep repeat (run bug tests)


#! one
uLOCAL_VARIABLE_ARRAY_INDEX one )

 
testing local variable array index potential bug
 
^flushoutput()

  $
$_jsonstring = ^'
  {
    "version": 23,
    "rowCount": 4,
    "anotherLevel":{ 
     "rows": [
       {
         "row": "zero",
         "info": "row 0 info"
       },
       {
         "row": "one",
         "info": "row 1 info"
       },
       {
         "row": "two",
         "info": "row 2 info"
       },
       {
         "row": "three",
         "info": "row 3 info"
       }
   ]
    }
  }'
 
   
$$_json = ^jsonparse($$_jsonstring)
   ^
jsontree($$_json)
   $
$_thisItem 0
   
$$_rgSize = ^length($$_json.rows
   ^
loop( $$_json.rowCount){
    \n looping 
for row $$_thisItem\n
    
$$_href = ^join\" https://www.bcbsal.org/web/provider-finder/ $$_json.anotherLevel.rows[$$_thisItem].row \" )
    
\n <a  target="_blank"> $$_json.anotherLevel.rows[$$_thisItem].info </a>
    $
$_thisItem += 1
   } 

When run on CS from 4/2/18 it produces:

swg: > run build tests one
KesTest:  Testing local variable array index potential bug   JSON=>
{ # jo-t1
"version": 23,
"rowCount": 4,
"anotherLevel": { # jo-t1001
"rows": [ # ja-t1002
{ # jo-t1003
"row": "zero",
"info": "row 0 info"
},
    { # jo-t1004
"row": "one",
"info": "row 1 info"
},
    { # jo-t1005
"row": "two",
"info": "row 2 info"
},
    { # jo-t1006
"row": "three",
"info": "row 3 info"
}
  ]
  }
}
<=JSON
\r\nlooping for row 0\r\n\r\n<a href = “https://www.bcbsal.org/web/provider-find
er/zero” target=” blank”> row 0 info </a>\r\nlooping for row 1\r\n\r\n<a href =
“https://www.bcbsal.org/web/provider-finder/one” target=” blank”> row 1 info </a
>\r\nlooping for row 2\r\n\r\n<a href = “https://www.bcbsal.org/web/provider-fin
der/two” target=” blank”> row 2 info </a>\r\nlooping for row 3\r\n\r\n<a href =
“https://www.bcbsal.org/web/provider-finder/three” target=” blank”> row 3 info <
/a>

when run on the latest version of CS it produces:

LISA:  Testing local variable array index potential bug   JSON=>
{ # jo-t1
"version": 23,
"rowCount": 4,
"anotherLevel": { # jo-t1001
"rows": [ # ja-t1002
{ # jo-t1003
"row": "zero",
"info": "row 0 info"
},
    { # jo-t1004
"row": "one",
"info": "row 1 info"
},
    { # jo-t1005
"row": "two",
"info": "row 2 info"
},
    { # jo-t1006
"row": "three",
"info": "row 3 info"
}
  ]
  }
}
<=JSON
\r\nlooping for row 0\r\n\r\n<a href = “https://www.bcbsal.org/web/provider-finder/evel.rows[$$ thisItem” target=” blank”> vel.rows[$$ thisItem\r\nlooping for row 0\r\n\r\n<a href = “https://www.bcbsal.org/web/provider-finder/evel.rows[$$ thisItem” target=” blank”> vel.rows[$$ thisItem\r\nlooping for row 0\r\n\r\n<a href = “https://www.bcbsal.org/web/provider-finder/evel.rows[$$ thisItem” target=” blank”> vel.rows[$$ thisItem\r\nlooping for row 0\r\n\r\n<a href = “https://www.bcbsal.org/web/provider-finder/evel.rows[$$ thisItem” target=” blank”> vel.rows[$$ thisItem

The difference between the two code bases seems to be the additional level in the json.

 

 
  [ # 4 ]

I cant speak to your real problems at present. Your code above is faulty.  You have:
  $$_rgSize = ^length($$_json.rows)
but rows is buried in anotherLevel

 

 
  [ # 5 ]

Bruce,

$$_rgSize = ^length($$_json.rows
   ^
loop( $$_json.rowCount)

$$_rgSize is not used. I removed it from the line and continue to have the same erroneous results. Also the trace does not show an error with the line $$_rgSize = ^length($$_json.rows). Although I don’t know why it wouldn’t show an error. Guess it’s an ^length(null). Anyway, removing the line did not have any effect on the result.

This code runs just fine on the April 2018 version of the engine. Response 2 of this thread has similar code that runs on the latest version of the engine and gives an expected result. Response 3 of this thread demonstrates the issue. The substantive difference between the two bits of code is moving the array another level down the json hierarchy.

Stephen G.

 

 
  [ # 6 ]

Sorry, was lazy. Given demands on my time, I stop at the first flaw.  I have figured out your real example and checked into git a SRC fix for it (but not recompiled all builds). I presume you can recompile on your own

 

 
  [ # 7 ]

Bruce,

I totally understand about the demands on your time. Thanks for taking a look at this for me.

I do not have the ability to compile the CS engine. oh oh

Stephen G.

 

 
  [ # 8 ]

OK. checked into git a couple of windows exes

 

 
  [ # 9 ]

BINGO!!

works like a charm now. Thanks Bruce.

Stephen G.

 

 
  [ # 10 ]

Bruce,

Can we get the LinuxChatScript64 rebuilt with this change too? I need it for my Docker container.

Thanks

 

 
  login or register to react