NAS - LUA scripts getting syntax error following CU4 (Cumulative Update 4) for 20.4 - invalid escape sequence
search cancel

NAS - LUA scripts getting syntax error following CU4 (Cumulative Update 4) for 20.4 - invalid escape sequence

book

Article ID: 252055

calendar_today

Updated On:

Products

DX Unified Infrastructure Management (Nimsoft / UIM)

Issue/Introduction

After applying UIM 20.4CU4 / NAS 9.36 we have a LUA script failing with an error like the following:

Error in line 43: invalid escape sequence near '"\{'

 

Environment

Release : 20.4

Cause

As part of the NAS upgrade, the underlying LUA library was upgraded to LUA 5.4 which resulted in a change to error handling for escape sequences.

Resolution

In older versions of NAS using LUA 5.1, if an incorrect escape sequence with the backslash character was used, the backslash would be ignored;  in the newer LUA (5.3 and higher) this throws a syntax error instead of silently failing.

In your LUA script, search for the sequence of characters given, such as "\{"  and change it as follows:

-- if you are trying to print a backslash use two backslashes: change "\{"  to "\\{"

-- if you do not actually need the backslash then you can just remove it -- LUA is telling you here that you are using a backslash unnecessarily.

For example, if your script has the following sequence:

print("Hello! \{This sequence appears in brackets\}")

In LUA 5.1 the backslash characters here would be ignored and the output would be:

Hello! {This sequence appears in brackets}

But in reality, the backslash characters are not needed here to produce this output, because the bracket does not need escaping in LUA.

The same sequence would produce the syntax error in LUA 5.4 to indicate that you have put a backslash where one is not required.  (If you are trying to print a backslash you need to use two.)

 

The following output is equivalent and works in LUA 5.4 and 5.1 the same way - the output produces the same as above with no backslashes and the brackets do not require escaping as long as the string is enclosed within double quotes:

print("Hello! {This sequence appears in brackets}")

On the other hand, if you wanted to print the following:

Hello! \{This sequence is surrounded by backslashes and brackets\}

Then you would need two:

print("Hello! \\{This sequence is surrounded by backslashes and brackets\\{")

 

Additional Information

The only escape sequences valid in LUA are as follows:

 '\a' (bell), '\b' (backspace), '\f' (form feed), '\n' (newline), '\r' (carriage return), '\t' (horizontal tab), '\v' (vertical tab), '\\' (backslash), '\"' (quotation mark [double quote]), and '\'' (apostrophe [single quote])

The following do NOT need to be escaped with a backslash:

 +     -     *     /     %     ^     #     &     ~     |     <<    >>    //     ==    ~=    <=    >=    <     >     =     (     )     {     }     [     ]     ::     ;     :     ,     .     ..    ...

LUA Manual