0

I want to use a string within a url:

some/url/<mystring>

My problem: mystring comes directly from a user input where it is allowed to type any special character including dangerous ones, like slash for example. I want to escape those.

EDIT: no, I do not want to escape HTML code. I want to escape the parts of a string, that could make the url directing elsewhere than to url/to/{input}. (for example / or ?)

Asqiir
  • 607
  • 1
  • 8
  • 23
  • URL-escape then! Be careful, if and when you receive those later on in any of your flows. – x80486 Jun 27 '18 at 16:02
  • 1
    Possible duplicate of [Recommended method for escaping HTML in Java](https://stackoverflow.com/questions/1265282/recommended-method-for-escaping-html-in-java) – Dragonthoughts Jun 27 '18 at 16:02

2 Answers2

0

Escape your url with String escapedURL=java.net.URLEncoder(url);

Read more about it here: https://docs.oracle.com/javase/7/docs/api/java/net/URLEncoder.html

Rainb
  • 1,965
  • 11
  • 32
-1

1.Fetch the String from user input

2.So safety-checking

3.if ok send it to html if not display a warning or not found error maybe

Derrick
  • 3,669
  • 5
  • 35
  • 50
Adou
  • 7
  • 5