BUG in FS C-Function: switch_separate_string(-)
Hi folks, I think that switch_separate_string(-) has a bug in splitting a string into array by a token: While parsing a char string into an array, [switch_separate_string(-)] always treats some substrings (which start with backslash char '\') as escaped chars, for example: even though char '\' has been escaped inside a constant string {"status=10&path=c:\\temp\\log\\&name=tom"}, [switch_separate_string(-)] treats its substring "\t" AS a single tab char; and substring "\&" AS a single char '&'. This result is definitely wrong! Here is an example that I tried on windows 2003 server: -- src codes: int nParams = 0; char* params[64] = {0}; char mystr[] = "status=10&path=c:\\temp\\log\\&name=tom"; switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "mystr: %s\n", mystr); nParams = switch_separate_string(mystr, '&', params, (sizeof(params) / sizeof(params[0]))); for (i=0; i < nParams; i++) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "[%d]: {%s}\n", i, params[i]); } -- printed log info: 2011-09-10 12:26:42.566383 [DEBUG] mod_xxx.c:981 mystr: status=10&path=c:\temp\log\&name=tom 2011-09-10 12:26:42.566383 [DEBUG] mod_xxx.c:985 [0]: {status=10} 2011-09-10 12:26:42.566383 [DEBUG] mod_xxx.c:985 [1]: {path=c: emp\log&name=tom} My comment: the above string 'mystr' is supposed to be parsed into a 3-element array {10, path=c:\temp\log\, tom}; however, [switch_separate_string(-)]parsed it into a 2-element array {10, path=c: emp\log&name=tom}. x.k.
Yes, this seems wrong, please add this issue to Jira. To get around (until it's fixed) it you can use / for the path, for instance C:/test/test.wav - Windows will handle frontslash as well as backslash when entering a path. /Peter ________________________________________ Från: freeswitch-users-bounces@lists.freeswitch.org [freeswitch-users-bounces@lists.freeswitch.org] för king2kin [xing2kin@yahoo.com] Skickat: den 10 september 2011 07:02 Till: freeswitch-users@lists.freeswitch.org Ämne: [Freeswitch-users] BUG in FS C-Function: switch_separate_string(-) Hi folks, I think that switch_separate_string(-) has a bug in splitting a string into array by a token: While parsing a char string into an array, [switch_separate_string(-)] always treats some substrings (which start with backslash char '\') as escaped chars, for example: even though char '\' has been escaped inside a constant string {"status=10&path=c:\\temp\\log\\&name=tom"}, [switch_separate_string(-)] treats its substring "\t" AS a single tab char; and substring "\&" AS a single char '&'. This result is definitely wrong! Here is an example that I tried on windows 2003 server: -- src codes: int nParams = 0; char* params[64] = {0}; char mystr[] = "status=10&path=c:\\temp\\log\\&name=tom"; switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "mystr: %s\n", mystr); nParams = switch_separate_string(mystr, '&', params, (sizeof(params) / sizeof(params[0]))); for (i=0; i < nParams; i++) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "[%d]: {%s}\n", i, params[i]); } -- printed log info: 2011-09-10 12:26:42.566383 [DEBUG] mod_xxx.c:981 mystr: status=10&path=c:\temp\log\&name=tom 2011-09-10 12:26:42.566383 [DEBUG] mod_xxx.c:985 [0]: {status=10} 2011-09-10 12:26:42.566383 [DEBUG] mod_xxx.c:985 [1]: {path=c: emp\log&name=tom} My comment: the above string 'mystr' is supposed to be parsed into a 3-element array {10, path=c:\temp\log\, tom}; however, [switch_separate_string(-)]parsed it into a 2-element array {10, path=c: emp\log&name=tom}. x.k. FreeSWITCH-users mailing list FreeSWITCH-users@lists.freeswitch.org http://lists.freeswitch.org/mailman/listinfo/freeswitch-users UNSUBSCRIBE:http://lists.freeswitch.org/mailman/options/freeswitch-users http://www.freeswitch.org !DSPAM:4e6af00032762055611955!
participants (2)
-
king2kin
-
Peter Olsson