Expand my Community achievements bar.

SOLVED

Colon support in resource resolver factory

Avatar

Level 2

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

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

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

View solution in original post

4 Replies

Avatar

Community Advisor

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/

Avatar

Level 2

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.

 

 

Avatar

Employee Advisor

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\\:

 

Avatar

Correct answer by
Community Advisor

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