[ 
https://issues.apache.org/jira/browse/SLING-13065?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18053277#comment-18053277
 ] 

Robin Brouns commented on SLING-13065:
--------------------------------------

There is a PR with a proposed fix in the previous comment, but I am not sure if 
this is the way forward. I don't know all use cases related to 
_rebaseResourcePath_ in the SlingUriBuilder and if we expect that the last `/` 
should be removed in this case yes or no. See: 
[https://github.com/apache/sling-org-apache-sling-api/pull/74]

> SlingUriBuilder parse results in java.lang.StringIndexOutOfBoundsException
> --------------------------------------------------------------------------
>
>                 Key: SLING-13065
>                 URL: https://issues.apache.org/jira/browse/SLING-13065
>             Project: Sling
>          Issue Type: Bug
>          Components: API
>    Affects Versions: API 3.0.4
>            Reporter: Robin Brouns
>            Priority: Major
>
>  
> When making use of SlingUriBuilder to parse or create an new instance from a 
> valid URI like:
> {code:java}
> SlingUriBuilder.parse("https://sling.apache.org/apidocs/sling12/";, resolver)
>         .build() {code}
> {code:java}
> URI input = new URI("https://sling.apache.org/apidocs/sling12/";);
> SlingUri testUri = SlingUriBuilder.createFrom(input, resolver)
>         .build(); {code}
> the SlingUriBuilder tries to _rebase_ the resource path. But the check for 
> adjusting the resource path, is not safe.
>  
> Calling it with above inputs leads to: 
> _java.lang.StringIndexOutOfBoundsException_
> {code:java}
> java.lang.StringIndexOutOfBoundsException: begin 17, end 16, length 17
>     at java.base/java.lang.String.checkBoundsBeginEnd(String.java:4608)
>     at java.base/java.lang.String.substring(String.java:2711)
>     at 
> org.apache.sling.api.uri.SlingUriBuilder.setPathWithDefinedResourcePosition(SlingUriBuilder.java:997)
>     at 
> org.apache.sling.api.uri.SlingUriBuilder.rebaseResourcePath(SlingUriBuilder.java:451)
>     at 
> org.apache.sling.api.uri.SlingUriBuilder.setPath(SlingUriBuilder.java:394) 
> {code}



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to