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

Add stripLeadingSlash to KiwiUrls #1108

Closed
sleberknight opened this issue Mar 8, 2024 · 0 comments · Fixed by #1109
Closed

Add stripLeadingSlash to KiwiUrls #1108

sleberknight opened this issue Mar 8, 2024 · 0 comments · Fixed by #1109
Assignees
Labels
new feature A new feature such as a new class, method, package, group of classes, etc.
Milestone

Comments

@sleberknight
Copy link
Member

sleberknight commented Mar 8, 2024

I needed to strip a leading slash from a URI the other day. I know, really difficult stuff. I assumed we had a method in KiwiUrls to do this simple task, but we only have a method to prepend a leading slash, and a method to strip a trailing slash.

I did the task using some methods in Apache Commons StringUtils and specifically the stripStart method, so StringUtils.stripStart("/some/random/path", "/") returns "some/random/path" as you expect. But, I also combined this with a check for null and blank strings, etc.

So, might as well have a dedicated method in KiwiUrls regardless of how simple it is. It should:

  • not allow null values (let it throw a NPE like prependLeadingSlash)
  • allow empty strings, returning empty in this case
  • trim leading and trailing whitespace, so that " /some/random/path " results in "some/random/path"
  • return the same value if there is no leading/trailing whitespace and no leading slash
@sleberknight sleberknight added the new feature A new feature such as a new class, method, package, group of classes, etc. label Mar 8, 2024
@sleberknight sleberknight added this to the 3.4.0 milestone Mar 8, 2024
@sleberknight sleberknight self-assigned this Mar 8, 2024
sleberknight added a commit that referenced this issue Mar 8, 2024
sleberknight added a commit that referenced this issue Mar 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
new feature A new feature such as a new class, method, package, group of classes, etc.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant