I’ve seen code generated by FreePBX which initializes null string as:
STRING="“
However it is not null string, it has two characters (two double quotes). Later this STRING is tested to see if it’s null like this:
IF($[”${STRING}"=""]?A:B)
which generates syntax error, and neither A nor B is returned. I also found in FreePBX code a funny trick, which works with really null string, and with “” string:
IF($[“foo${STRING}”=“foo”]?A:B)
even though it generates syntax error, proper value is returned. More tests:
exten => dlocal,1,Set(TEST="")
exten => dlocal,n,Set(TEST1=${IF($["${TEST}"=""]?TRUE1:FALSE1)})
exten => dlocal,n,Set(TEST2=${IF($["foo${TEST}"="foo"]?TRUE2:FALSE2)})
exten => dlocal,n,Set(TEST3=${IF($["${TEST}foo"="foo"]?TRUE3:FALSE3)})
exten => dlocal,n,Set(TEST4=${IF($[${TEST}=""]?TRUE4:FALSE4)})
exten => dlocal,n,Set(TEST=)
exten => dlocal,n,Set(TEST5=${IF($[${TEST}=""]?TRUE5:FALSE5)})
Result in logs:
[May 19 22:08:11] VERBOSE[18877] pbx.c: -- Executing [dlocal@macro-dial-one:1] Set("SIP/586006161-00000032", "TEST=""") in new stack
[May 19 22:08:11] WARNING[18877] ast_expr2.fl: ast_yyerror(): syntax error: syntax error, unexpected '<token>', expecting $end; Input:
""""=""
^
[May 19 22:08:11] WARNING[18877] ast_expr2.fl: If you have questions, please refer to https://wiki.asterisk.org/wiki/display/AST/Channel+Variables
[May 19 22:08:11] WARNING[18877] func_logic.c: Syntax IF(<expr>?[<true>][:<false>]) (expr must be non-null, and either <true> or <false> must be non-null)
[May 19 22:08:11] WARNING[18877] func_logic.c: In this case, <expr>='', <true>='TRUE1', and <false>='FALSE1'
[May 19 22:08:11] VERBOSE[18877] pbx.c: -- Executing [dlocal@macro-dial-one:2] Set("SIP/586006161-00000032", "TEST1=") in new stack
[May 19 22:08:11] WARNING[18877] ast_expr2.fl: ast_yyerror(): syntax error: syntax error, unexpected '<token>', expecting $end; Input:
"foo"""="foo"
^
[May 19 22:08:11] WARNING[18877] ast_expr2.fl: If you have questions, please refer to https://wiki.asterisk.org/wiki/display/AST/Channel+Variables
[May 19 22:08:11] VERBOSE[18877] pbx.c: -- Executing [dlocal@macro-dial-one:3] Set("SIP/586006161-00000032", "TEST2=TRUE2") in new stack
[May 19 22:08:11] WARNING[18877] ast_expr2.fl: ast_yyerror(): syntax error: syntax error, unexpected '<token>', expecting $end; Input:
"""foo"="foo"
^
[May 19 22:08:11] WARNING[18877] ast_expr2.fl: If you have questions, please refer to https://wiki.asterisk.org/wiki/display/AST/Channel+Variables
[May 19 22:08:11] WARNING[18877] func_logic.c: Syntax IF(<expr>?[<true>][:<false>]) (expr must be non-null, and either <true> or <false> must be non-null)
[May 19 22:08:11] WARNING[18877] func_logic.c: In this case, <expr>='', <true>='TRUE3', and <false>='FALSE3'
[May 19 22:08:11] VERBOSE[18877] pbx.c: -- Executing [dlocal@macro-dial-one:4] Set("SIP/586006161-00000032", "TEST3=") in new stack
[May 19 22:08:11] VERBOSE[18877] pbx.c: -- Executing [dlocal@macro-dial-one:5] Set("SIP/586006161-00000032", "TEST4=TRUE4") in new stack
[May 19 22:08:11] VERBOSE[18877] pbx.c: -- Executing [dlocal@macro-dial-one:6] Set("SIP/586006161-00000032", "TEST=") in new stack
[May 19 22:08:11] WARNING[18877] ast_expr2.fl: ast_yyerror(): syntax error: syntax error, unexpected '=', expecting $end; Input:
=""
^
[May 19 22:08:11] WARNING[18877] ast_expr2.fl: If you have questions, please refer to https://wiki.asterisk.org/wiki/display/AST/Channel+Variables
[May 19 22:08:11] WARNING[18877] func_logic.c: Syntax IF(<expr>?[<true>][:<false>]) (expr must be non-null, and either <true> or <false> must be non-null)
[May 19 22:08:11] WARNING[18877] func_logic.c: In this case, <expr>='', <true>='TRUE5', and <false>='FALSE5'
[May 19 22:08:11] VERBOSE[18877] pbx.c: -- Executing [dlocal@macro-dial-one:7] Set("SIP/586006161-00000032", "TEST5=") in new stack
Asterisk version: 1.8.4
Why would anyone use STRING=""? Maybe in earlier versions of Asterisk it was a null string?
Related bug report: http://www.freepbx.org/v2/ticket/5159