Mar 17, 2015; 18:25
Sprague, Gary
Re: [EXTERNAL] RegExp->AppendReplacement throwing error U_INDEX_OUTOFBOUNDS_ERROR
BTW, the "<smb://]>” mentions in the sample code were not part of my posting. Apparently either my email client or other system along the chain inserted this code. If you remove them, the rest of the code should be accurate.
Gary Sprague
TV Systems Engineer
HSN, 1 HSN Drive, St. Petersburg, FL 33729
Office 727.872.4489
Gary.Sprague@hsn.net<mailto:Gary.Sprague@hsn.net>
On Mar 17, 2015, at 2:07 PM, Sprague, Gary <Gary.Sprague@hsn.net<mailto:Gary.Sprague@hsn.net>> wrote:
Hi All.
Some months ago I had worked up a new way to parse JSON data which relied pretty heavily on regular expressions. One piece of the code was designed to take strings that contained braces or brackets and escape them prior to processing. Over this past weekend I discovered that this piece of the code was not working. (clearly I did not do enough testing on this) Someone at my company had inserted braces into a field that was passed to us in a JSON feed that forced exposure of the issue.
I get the following error with braces inside the string (meeting the regular expression match below):
ERROR: U_INDEX_OUTOFBOUNDS_ERROR at: appendreplacement with params: ...
So here is the portion of code that is breaking:
/* First we find "value" strings that may have reserved characters that are not escaped. They are: { } [ ] */
local('myre' = regexp(
-find='(?<=:)\\s*"(?:(?:(?<=\\\\)["{}\\[\\]<smb://]>]|<smb://]<smb://]>]|>[^"])*(?:(?<!\\\\)[{}\\[\\]]<smb://]]><smb://]]<smb://]]>>)+(?:(?<=\\\\)["{}\\[\\]<smb://]>]|<smb://]<smb://]>]|>[^"])*)+?"',
-input=#_json)
);
while(#myre->find);
local('_replacement' = #myre->matchstring);
// We replace any: { } [ ] that are not escaped in the matchstring
#_replacement->replace(regexp(-find='((?<!\\\\)[{}\\[\\]]<smb://]]><smb://]]<smb://]]>>){1}',-replace='\\\\\\1'));
// Now we ensure that all backslashes are doubled because the first backslash will be removed on append.
#_replacement->replace(regexp(-find='(\\\\){1}',-replace='\\\\\\\\'));
#myre->appendreplacement(#_replacement);
/while;
#myre->appendtail;
/* Now we continue by passing the result above. */
#_json = #myre->output;
So, at first I figured that I had done something wrong, as the examples seem vague. Further researching I found examples of “appendreplacement” replacing with strings just as I am doing in my code. (Fletchers example reflects this here: http://www.lassotalk.com/Re-Another-Regex-problem.lasso?169634 )
So in my testing I get the following results:
* #myre->appendreplacement(#_replacement); Returns the error: ERROR: U_INDEX_OUTOFBOUNDS_ERROR
* #myre->appendreplacement(‘\\0'<smb://0'><smb://0'<smb://0'>>); Replaces my string with a “0” (as per example on page 356 of the Lasso 8.6 Language Guide)
* #myre->appendreplacement(‘\$0'); Replaces my string with the match string.
Has anyone else had experience (or issues) with this method? Is this a bug or a documentation issue?
I am running Lasso 8.6.2 on Windows Server 2008 Standard. (I have also tested with latest Lasso 8.6.3 on the same OS)
Thanks in advance for any help.
Gary Sprague
TV Systems Engineer
HSN, 1 HSN Drive, St. Petersburg, FL 33729
Office 727.872.4489
Gary.Sprague@hsn.net<mailto:Gary.Sprague@hsn.net><mailto:Gary.Sprague@hsn.net>
#############################################################
This message is sent to you because you are subscribed to
the mailing list Lasso Lasso@lists.lassosoft.com<mailto:Lasso@lists.lassosoft.com>
Official list archives available at http://www.lassotalk.com
To unsubscribe, E-mail to: <Lasso-unsubscribe@lists.lassosoft.com<mailto:Lasso-unsubscribe@lists.lassosoft.com>>
Send administrative queries to <Lasso-request@lists.lassosoft.com<mailto:Lasso-request@lists.lassosoft.com>>
#############################################################
This message is sent to you because you are subscribed to
the mailing list Lasso Lasso@lists.lassosoft.com
Official list archives available at http://www.lassotalk.com
To unsubscribe, E-mail to: <Lasso-unsubscribe@lists.lassosoft.com>
Send administrative queries to <Lasso-request@lists.lassosoft.com>