[MAGNOLIA-2659] info.magnolia.cms.beans.config.RegexpVirtualURIMapping error with high number of groups Created: 10/Mar/09  Updated: 23/Jan/13  Resolved: 29/May/09

Status: Closed
Project: Magnolia
Component/s: core
Affects Version/s: None
Fix Version/s: 4.1

Type: Bug Priority: Major
Reporter: Manuel Molaschi Assignee: Magnolia International
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Attachments: Text File MAGNOLIA-2659.patch    
Template:
Acceptance criteria:
Empty
Task DoD:
[ ]* Doc/release notes changes? Comment present?
[ ]* Downstream builds green?
[ ]* Solution information and context easily available?
[ ]* Tests
[ ]* FixVersion filled and not yet released
[ ]  Architecture Decision Record (ADR)
Bug DoR:
[ ]* Steps to reproduce, expected, and actual results filled
[ ]* Affected version filled
Date of First Response:

 Description   

I found that using a regexp with a high number of groups (>10) in a RegexpVirtualURIMapping can cause a problem when replacing group instances with matches.

if you change
int matcherCount = matcher.groupCount();
for (int j = 0; j <= matcherCount; j++) {

in
int matcherCount = matcher.groupCount();
for (int j = matcherCount; j >= 0; j--){

it works.

This problem happens because the procedure replaces (in example) all "$2" occurrences making impossible to find (and replace) the "$20"



 Comments   
Comment by Magnolia International [ 10/Mar/09 ]

Hmm, looking at the code quickly, I don't even see why we don't use the regex api to do the subsitutation; however, I'm not convinced group numbers higher than 9 will be supported in that case either.
It'd help if you could provide a few testcases demonstrating how the current code fails for you and what it should do instead.

Cheers,

Comment by manuel.molaschi [ 11/Mar/09 ]

I have a regexp with pattern
/((prefix1)|(prefix2)|......|(prefixN))/(.)(/(.))?
which ends to
redirect:http://..../$28?....$n...$m

Suppose that matching group n° 2 is "XXX" and n° 28 is "YYY"
with actual code $2 is replaced before replacing $28 and then the result is
redirect:http://..../XXX8?....$n...$m
insteadof
redirect:http://..../YYY?....$n...$m

Comment by Magnolia International [ 12/Mar/09 ]

Added a testcase, and a commented out one that shows this fails with more than 9 groups.
I have a fix locally, but more tests would help ensuring corner cases won't fail.

Comment by Magnolia International [ 29/May/09 ]

Well, patch applied; feel free to pitch in with more tests if this fails or if some corner case needs to be tested !
Thanks for the report !

Generated at Mon Feb 12 03:38:51 CET 2024 using Jira 9.4.2#940002-sha1:46d1a51de284217efdcb32434eab47a99af2938b.