Questions tagged [stringescapeutils]

'StringEscapeUtils' is a java class in the Text subproject of the Commons project from Apache Software Foundation (ASF). The class was formerly in the Lang subproject. The purpose of the class is to escape and unescape strings for Java, Java Script, HTML and XML. Use this tag for questions regarding the StringEscapeUtils class.

StringEscapeUtils is a java class in the Apache Commons Text project. The class was originally part of the Commons Lang project but was migrated to the Commons Text project. The class is used to convert characters in strings to their equivalent entity and vice-versa. This is known as escaping (or unescaping) characters. For example the [HTML] entity for the & (ampersand) character is &. Hence class StringEscapeUtils contains methods for converting & to & as well as methods for converting & to &. The class also contains methods for escaping and unescaping characters in JavaScript and XML as well as HTML.

82 questions
0
votes
1 answer

How to unescape JSON/Java with support to ampersand?

Background I need to parse some string from HTML that is of a URL (seems it's inside JSON), so I tried to use org.apache.commons.text.StringEscapeUtils.unescapeJson. An example of such a URL started with this as the…
android developer
  • 114,585
  • 152
  • 739
  • 1,270
0
votes
2 answers

How to convert '(' to unicode(\u0028) in java?

I want to convert following string to an escaped String. I am using StringEscapeUtils.escapeJava(), but it didn't escape the brackets. For example: val str =…
0
votes
1 answer

Java code missing elements: Properties file to hashmap [Escape character issue]

I have written a code wherein i am reading a properties file and adding the values to a hashmap and using it in a specific format to call an API. Problem is slash space (\ ) is replaced with a space. Adding the code: public class propertfile { …
User1515
  • 11
  • 7
0
votes
1 answer

Unable to unesape consecutive escape char in org.apache.commons.lang3.StringEscapeUtils.unescapeXml()

Unable to unescape consecutive escape char like <errors>. Below is the sample code: String error = "&lt;errors&gt;"; String out = org.apache.commons.lang3.StringEscapeUtils.unescapeXml(error); …
0
votes
0 answers

How do I write the below string in between quotes?

Looking to put the below string in between quotes for a json key value pair. index=xyz_* sourcetype=abc_* /api/v2/abc/words/process/ \"status\":\"timeout\" OR \"status\":\"finished\" | rex field=_raw "\"status\":\"(?.{9})" |…
shiva nara
  • 43
  • 8
0
votes
1 answer

jQuery AJAX is converting the string escape from %20 to +

I have a jQuery AJAX function that saves an image path to the database. Here is an examples parameter: var data = {}; data['url'] = "Path%20to%20URL"; If there is a space or %20, it will be saved as "Path%20to%20URL" in the database. I haven't…
TechPro
  • 1
  • 1
0
votes
1 answer

Scala - Couldn't remove double quotes for Key -> value "{}" braces while building Json

Scala - Couldn't remove double quotes for "{}" braces while building Json import scala.util.Random import math.Ordered.orderingToOrdered import math.Ordering.Implicits.infixOrderingOps import play.api.libs.json._ import…
0
votes
1 answer

How to handle escape characters in pyspark. Trying to replace escape character with NULL, when column value is '\026' in dataframe

How to handle escape characters in pyspark. Trying to replace escape character with NULL '\026' is randomly spreadout through all the columns and I have replace to '\026' with NULL across all columns below is my sample input…
EVR
  • 31
  • 4
0
votes
1 answer

How to prevent Put API in your controller from XSS attacks reflected in CheckMarx scans?

I ran a CheckMarx Scan on my repository and it gave quite many potential Reflected XSS attack results. Here is the code for my controller : @PutMapping("/calculate") public UpdatedResponse calculateModel( @RequestBody ModelDocument…
DujSn28
  • 13
  • 3
0
votes
0 answers

Escape html except some special characters

With the goal to prevent html code injection and cross-site scripting, there is a filter built for service requests to escape some characters using: StringEscapeUtils.escapeHtml(text) However, this is also escaping some UTF8 characters like äöü.…
orcl user
  • 167
  • 1
  • 4
  • 9
0
votes
1 answer

How to check if String should be escaped in Java

I want to check if a specific String should be escaped before really performing any escaping mechanism. for example: if the String is "msg\t" so I want to escape it but if the String is "msg\\t" meaning it is already escaped or for example "msg"…
Tal Levi
  • 363
  • 1
  • 6
  • 22
0
votes
0 answers

java.lang.NoClassDefFoundError: org/apache/commons/text/StringEscapeUtils

I am trying to call a method, but I keep getting the following error: Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/text/StringEscapeUtils From what I understood I was supposed to have this dependency in my…
csymvoul
  • 677
  • 3
  • 15
  • 30
0
votes
1 answer

What is the difference between unescapeJava and unescapeJson from StringEscapeUtils

As per the StringEscapeUtils documentation, looks like both these methods unescapeJson and unescapeJava does the similar thing. I tried using both methods it works fine as below: Example: String input =…
TheCodeCache
  • 820
  • 1
  • 7
  • 27
0
votes
1 answer

Java escape XML token strings

The answer for most Character encoding is Apache StringEscapeUtils in the commons.text version. Agree. Can be used to escape the strings between the xml tags. But how do I escape the xml tokens themselves? Allowed chars are simple:…
Werner Daehn
  • 577
  • 6
  • 16
0
votes
0 answers

Replace html encoded characters in Java

I want to convert the string

üè

to

üé

, but both StringEscapeUtils.unescapeHtml4() (from org.apache.commons.text) and HtmlUtils.unescapeHtml() (from org.springframework.web.util) convert it to <p>üè</p>. Is there…
Nickkk
  • 2,261
  • 1
  • 25
  • 34