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

ServletContext getContextPath() does not end with forward slash. #14345

Closed
pmd1nh opened this issue Oct 6, 2020 · 6 comments · Fixed by #14400
Closed

ServletContext getContextPath() does not end with forward slash. #14345

pmd1nh opened this issue Oct 6, 2020 · 6 comments · Fixed by #14400
Assignees
Labels
bug This bug is not present in a released version of Open Liberty in:Web Components POC Approved release bug This bug is present in a released version of Open Liberty release:21005 team:Sirius

Comments

@pmd1nh
Copy link
Member

pmd1nh commented Oct 6, 2020

ServletContext.getContextPath() - The context path always comes first in a request URI. The path starts with a "/" character but does not end with a "/" character.

Currently getContextPath() does not check for the ending slash and includes it in the return.
Fix: check and remove the ending slash. An info will be logged when this happens. The flow continues.

Workaround: remove the configured ending / in the context root.

@pmd1nh pmd1nh self-assigned this Oct 6, 2020
@pmd1nh pmd1nh added team:Sirius bug This bug is not present in a released version of Open Liberty in:Web Components labels Oct 6, 2020
@pmd1nh
Copy link
Member Author

pmd1nh commented Oct 8, 2020

#14400

@pnicolucci pnicolucci added this to General Issues in Web Tier Team via automation Oct 20, 2020
@pmd1nh pmd1nh added the release bug This bug is present in a released version of Open Liberty label Oct 21, 2020
@pmd1nh
Copy link
Member Author

pmd1nh commented Oct 21, 2020

Additional information:

https://jakarta.ee/specifications/platform/8/apidocs/javax/servlet/ServletContext.html#getContextPath--

=====
String getContextPath()

Returns the context path of the web application.

The context path is the portion of the request URI that is used to select the context of the request. The context path always comes first in a request URI. If this context is the "root" context rooted at the base of the Web server's URL name space, this path will be an empty string. Otherwise, if the context is not rooted at the root of the server's name space, the path starts with a / character but does not end with a / character.

It is possible that a servlet container may match a context by more than one context path. In such cases the HttpServletRequest.getContextPath() will return the actual context path used by the request and it may differ from the path returned by this method. The context path returned by this method should be considered as the prime or preferred context path of the application.

=====

@pmd1nh pmd1nh changed the title ServletContext getContextPath() should not end with trailing forward slash. ServletContext getContextPath() should not end with forward slash. Oct 21, 2020
@pmd1nh pmd1nh changed the title ServletContext getContextPath() should not end with forward slash. ServletContext getContextPath() does not end with forward slash. Oct 21, 2020
@mbroz2
Copy link
Member

mbroz2 commented Oct 28, 2020

The vote for "Do we Agree to change the default behavior of future versions of Java Servlet (starting with 5.0) to strip the trailing / (forward slash) if present" has been POC Approved.

The vote for whether we want to change the default behavior for the existing versions of Java Servlet has also been POC Approved

@bmarwell
Copy link
Contributor

@mbroz2 @pnicolucci can this be merged at some point? :)

@pnicolucci
Copy link
Member

@bmarwell yes we're working to get this delivered in the next couple of days! Sorry for the delay!

Web Tier Team automation moved this from General Issues to Completed Tasks Apr 21, 2021
@pmd1nh
Copy link
Member Author

pmd1nh commented Apr 21, 2021

merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This bug is not present in a released version of Open Liberty in:Web Components POC Approved release bug This bug is present in a released version of Open Liberty release:21005 team:Sirius
Projects
Archived in project
Web Tier Team
  
Completed Tasks
Development

Successfully merging a pull request may close this issue.

5 participants