Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

StringIndexOutOfBoundsException in Decoder.decode #258

Open
silvafabio opened this issue Jan 27, 2018 · 2 comments
Open

StringIndexOutOfBoundsException in Decoder.decode #258

silvafabio opened this issue Jan 27, 2018 · 2 comments

Comments

@silvafabio
Copy link
Contributor

silvafabio commented Jan 27, 2018

Hi Guys.

If the "path" variable has an space at the last position (that will be converted to '+' in line 31) an "java.lang.StringIndexOutOfBoundsException: String index out of range" occour in line 36 of org.ocpsoft.urlbuilder.util.Decoder#decode(final CharSequence path, final boolean query).

I think the problem is the "pos++" or an missing "continue" after that.

I'am using:

    <!-- https://mvnrepository.com/artifact/org.ocpsoft.rewrite/rewrite-servlet -->
    <dependency>
        <groupId>org.ocpsoft.rewrite</groupId>
        <artifactId>rewrite-servlet</artifactId>
        <version>3.4.1.Final</version>
    </dependency>
    <!-- https://mvnrepository.com/artifact/org.ocpsoft.rewrite/rewrite-integration-faces -->
    <dependency>
        <groupId>org.ocpsoft.rewrite</groupId>
        <artifactId>rewrite-integration-faces</artifactId>
        <version>3.4.1.Final</version>
    </dependency>
@silvafabio
Copy link
Contributor Author

After fix that, take a look at #210 because it's could be the cause as my stacktrace is too similar:

Stack Trace: javax.faces.FacesException: Error during [OutboundRewrite [flow=UN_HANDLED, outboundURL=/produtos.xhtml?categoria=todas-as-categorias&descricao=teste%2B&fabricante=todas-as-marcas&tipo=todos-os-tipos, dispatchResource=null]] while executing rule [.addRule(Join.path("/{categoria}/{tipo}/{fabricante}/{descricao}").to("/produtos.xhtml")).withPriority(10)] at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:89) at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101) at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118) at javax.faces.webapp.FacesServlet.service(FacesServlet.java:603) at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1550) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:343) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:217) at org.ocpsoft.rewrite.servlet.RewriteFilter.doFilter(RewriteFilter.java:226) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:256) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:217) at org.apache.catalina.core.ApplicationDispatcher.doInvoke(ApplicationDispatcher.java:807) at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:671) at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:505) at org.apache.catalina.core.ApplicationDispatcher.doDispatch(ApplicationDispatcher.java:476) at org.apache.catalina.core.ApplicationDispatcher.dispatch(ApplicationDispatcher.java:355) at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:305) at org.ocpsoft.rewrite.servlet.impl.HttpRewriteResultHandler.handleResult(HttpRewriteResultHandler.java:42) at org.ocpsoft.rewrite.servlet.RewriteFilter.rewrite(RewriteFilter.java:297) at org.ocpsoft.rewrite.servlet.RewriteFilter.doFilter(RewriteFilter.java:198) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:256) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:217) at br.com.vanguardati.commerce.servlets.filters.FacesServletFiltro.doFilter(FacesServletFiltro.java:62) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:256) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:217) at br.com.vanguardati.commerce.servlets.filters.CharSetFiltro.doFilter(CharSetFiltro.java:80) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:256) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:217) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:279) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175) at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:655) at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:595) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:161) at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:331) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:231) at com.sun.enterprise.v3.services.impl.ContainerMapper$AdapterCallable.call(ContainerMapper.java:317) at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:195) at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:860) at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:757) at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:1056) at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:229) at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:137) at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:104) at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:90) at com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:79) at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:54) at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:59) at com.sun.grizzly.ContextTask.run(ContextTask.java:71) at com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:532) at com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:513) at java.lang.Thread.run(Thread.java:745) Caused by: org.ocpsoft.rewrite.exception.RewriteException: Error during [OutboundRewrite [flow=UN_HANDLED, outboundURL=/produtos.xhtml?categoria=todas-as-categorias&descricao=teste%2B&fabricante=todas-as-marcas&tipo=todos-os-tipos, dispatchResource=null]] while executing rule [.addRule(Join.path("/{categoria}/{tipo}/{fabricante}/{descricao}").to("/produtos.xhtml")).withPriority(10)] at org.ocpsoft.rewrite.servlet.impl.DefaultHttpRewriteProvider.rewriteOutbound(DefaultHttpRewriteProvider.java:410) at org.ocpsoft.rewrite.servlet.impl.DefaultHttpRewriteProvider.rewriteHttp(DefaultHttpRewriteProvider.java:92) at org.ocpsoft.rewrite.servlet.http.HttpRewriteProvider.rewrite(HttpRewriteProvider.java:43) at org.ocpsoft.rewrite.servlet.impl.HttpRewriteWrappedResponse.rewrite(HttpRewriteWrappedResponse.java:434) at org.ocpsoft.rewrite.servlet.impl.HttpRewriteWrappedResponse.encodeURL(HttpRewriteWrappedResponse.java:393) at com.sun.faces.context.ExternalContextImpl.encodeActionURL(ExternalContextImpl.java:531) at com.sun.faces.application.view.MultiViewHandler.getRedirectURL(MultiViewHandler.java:401) at org.ocpsoft.rewrite.faces.RewriteViewHandler.getRedirectURL(RewriteViewHandler.java:183) at com.sun.faces.application.NavigationHandlerImpl.handleNavigation(NavigationHandlerImpl.java:164) at org.ocpsoft.rewrite.faces.RewriteNavigationHandler.handleNavigation(RewriteNavigationHandler.java:64) at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:129) at javax.faces.component.UICommand.broadcast(UICommand.java:315) at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:786) at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1251) at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:81) ... 49 more Caused by: java.lang.StringIndexOutOfBoundsException: String index out of range: 6 at java.lang.String.charAt(String.java:658) at org.ocpsoft.urlbuilder.util.Decoder.decode(Decoder.java:36) at br.com.vanguardati.commerce.rewrites.ProdutosRewrite$1.transpose(ProdutosRewrite.java:122) at br.com.vanguardati.commerce.rewrites.ProdutosRewrite$1.transpose(ProdutosRewrite.java:119) at org.ocpsoft.rewrite.param.DefaultParameterValueStore.submit(DefaultParameterValueStore.java:95) at org.ocpsoft.rewrite.param.RegexParameterizedPatternParser$RegexParameterizedPatternMatchResult.submit(RegexParameterizedPatternParser.java:426) at org.ocpsoft.rewrite.servlet.config.Query$2.evaluateHttp(Query.java:164) at org.ocpsoft.rewrite.servlet.config.HttpCondition.evaluate(HttpCondition.java:44) at org.ocpsoft.rewrite.config.And.evaluate(And.java:78) at org.ocpsoft.rewrite.config.DefaultConditionBuilder$1.evaluate(DefaultConditionBuilder.java:46) at org.ocpsoft.rewrite.servlet.config.rule.Join.evaluate(Join.java:227) at org.ocpsoft.rewrite.config.RuleBuilder.evaluate(RuleBuilder.java:154) at org.ocpsoft.rewrite.servlet.impl.DefaultHttpRewriteProvider.rewriteOutbound(DefaultHttpRewriteProvider.java:367) ... 63 more

@chkal
Copy link
Member

chkal commented Jan 27, 2018

Thanks a lot! I agree that a continue after the pos++ should fix the problem

// '+' -> ' ' for query strings
if (query && path.charAt(pos) == '+') {
decoded.append(' ');
pos++;
}

I don't find much time to work on Rewrite any more. But pull requests are welcome. There is also a DecoderTest. So verifying the fix should be easy.

silvafabio added a commit to silvafabio/rewrite that referenced this issue Jan 28, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants