DX Unified Infrastructure Management

 View Only
  • 1.  urlencoding in nas script

    Posted Dec 02, 2015 06:56 AM

    Hi I'm trying to do urlencoding in nas script to envoke some external commend.

    One of the key requirement is to convert char to ASCII code. In LUA its done by "string.byte" function but under NAS no such function is available.

    Can anyone let me know how to achieve same in NAS.

     

    -Mohinder Singh



  • 2.  Re: urlencoding in nas script

    Posted Dec 06, 2015 01:58 PM

    I'd swear that I'v seen this work if that helps.

     

    I've also been told that the LUA implementation in the nas is the same code/version as in the command line so I'd expect it to work the same.

     

    Does http://stackoverflow.com/questions/24190608/lua-string-byte-for-non-ascii-characters  potentially apply to what you are trying to do? In particular, note the alternative notation of variable:byte(1, -1)

     

    -Garin



  • 3.  Re: urlencoding in nas script

    Posted Dec 08, 2015 06:19 AM

    Hi ,

    I am using given test function

    ==============================

    function url_encode(s)

          s = string.gsub(s, "([^%w ])", function (c)

                return string.format("%%%02X", string.byte(c))

              end)

          s = string.gsub(s, " ", "+")

          return s

    end

     

    mystr='This is test string'

    printf(url_encode(mystr))

    ==============================

    Without any spl char it works , but as soon as I change mystr = 'This is @ test string' ,  string.byte() function fail because of spl. char.