Colon support in resource resolver factory | Community
Skip to main content
Level 2
June 26, 2023
Solved

Colon support in resource resolver factory

  • June 26, 2023
  • 3 replies
  • 1377 views

Hi,

 

Under urls mapping in resource resolver factory, I am trying to put a rule with complete domain name e.g. /content/abc/us/en\.html < https://abc.com/ but this rule is getting skipped and have no effect. On further analysis, it seems colon (:) after the https is the culprit. If I remove it from the rule then this rule works as expected. I tried to escape colon by putting single backslash (e.g. \:) as well as double backslash (\\:) but no luck. Does anyone know how to escape such characters in the resource resolver factory?

 

thanks

Neeraj

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by Nupur_Jain

Hi @nbhart 

 

I decompiled the org.apache.sling.resourceresolver.impl.ResourceResolverFactoryActivator class which is providing the configuration for resource resolver mapping. I have found that when it reads the list of mapping provided by us, it divides the mapping into 3 parts with help of regex that prepart, operator and postpart. 
The regex internally used is "(.+)([:<>])(.+)"
which means when you are providing your mapping which is /content/abc/us/en\.html < https://abc.com/
It finds out the parts as Prepart as "/content/abc/us/en.html<https", operator as ":" and postpart as "//abc.com/".
In short, you can not specify your mapping as it will always interpret it wrong due to regex.

There is no way to specify your mapping atleast from Resource resolver configuration.

 

Thanks,

Nupur

3 replies

Tanika02
Level 7
June 26, 2023

Hello @nbhart - 

 

  • In the Apache Sling Resource Resolver Factory configuration, you can use regular expressions to define URL mappings. However, certain characters, like colon (':'), have special meaning in regular expressions and need to be properly escaped.
  • To escape the colon character in your URL mapping rule, you can use the Unicode representation of the colon character, which is \u003A. Here's how you can modify your rule to include the escaped colon:/content/abc/us/en\.html < https\u003A//abc.com/
nbhartAuthor
Level 2
June 27, 2023

It seems the encoded colon is not recognized by the browser. When I put the generated url in browser, I got the below error

 

This site can’t be reached
Check if there is a typo in httpsu003a.

 

 

ManviSharma
Adobe Employee
Adobe Employee
June 26, 2023

Hi,

 

To escape special characters like colon (:) in the URL mapping rule of the resource resolver factory, you can use the backslash () followed by the colon. However, in some cases, additional escaping might be required.

Here's an example of how you can escape the colon in the rule:

/content/abc/us/en\.html\:

 

If this doesn't work, you can try using double backslashes (\) to escape the colon:

/content/abc/us/en\\.html\\:

 

Nupur_Jain
Adobe Employee
Nupur_JainAdobe EmployeeAccepted solution
Adobe Employee
June 27, 2023

Hi @nbhart 

 

I decompiled the org.apache.sling.resourceresolver.impl.ResourceResolverFactoryActivator class which is providing the configuration for resource resolver mapping. I have found that when it reads the list of mapping provided by us, it divides the mapping into 3 parts with help of regex that prepart, operator and postpart. 
The regex internally used is "(.+)([:<>])(.+)"
which means when you are providing your mapping which is /content/abc/us/en\.html < https://abc.com/
It finds out the parts as Prepart as "/content/abc/us/en.html<https", operator as ":" and postpart as "//abc.com/".
In short, you can not specify your mapping as it will always interpret it wrong due to regex.

There is no way to specify your mapping atleast from Resource resolver configuration.

 

Thanks,

Nupur