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
65
votes
4 answers

How to add org.apache.commons.lang3 to AndroidStudio with gradle

Due to this question I want to use class StringEscapeUntils in package org.apache.commons.lang3. But when I try to import Apache lib by add line compile 'org.apache.commons:commons-collections4:4.0' to build.grade file then can not import the class…
ThaiPD
  • 3,503
  • 3
  • 30
  • 48
14
votes
4 answers

When i need to escape Html string?

In my legacy project i can see the usage of escapeHtml before string is sent to browser. StringEscapeUtils.escapeHtml(stringBody); I know from api doc what escapeHtml does.here is the example given:- For example: "bread" & "butter" becomes:…
M Sach
  • 33,416
  • 76
  • 221
  • 314
6
votes
4 answers

StringEscapeUtils.escapeXml is converting utf8 characters which it should not

escapeXml function is converting ѭ Ѯ to ѭ Ѯ which I guess it should not. What I read is that it Supports only the five basic XML entities (gt, lt, quot, amp, apos). Is there a function that only converts these five basic xml…
Mady
  • 5,016
  • 7
  • 35
  • 46
5
votes
4 answers

How can I escape all escape-worthy characters in one line of code?

Based on what I see here (accepted answer), it would seem that I could escape strings by doing this: string s = "Woolworth's"; string t = Regex.Escape(s); MessageBox.Show(t); ...but stepping through that, I see no difference between s and t (I…
B. Clay Shannon-B. Crow Raven
  • 8,547
  • 144
  • 472
  • 862
5
votes
2 answers

StringEscapeUtils escapeHtml

Is there a difference between org.apache.commons.lang.StringEscapeUtils.escapeHtml and org.apache.commons.lang3.StringEscapeUtils.escapeHtml4 ?
mathematician
  • 1,942
  • 5
  • 19
  • 22
3
votes
2 answers

Standard library to escape strings (without prepared statements)

I'm searching for a Java standard library to escape strings before using them in a SQL statement. This is mainly to prevent errors and to prevent SQL injection, too. Unfortunately, I will not be able to use prepared statements as is is suggested in…
user1040128
  • 31
  • 1
  • 2
3
votes
2 answers

String contents are same but equals method returns false

I am using StringEscapeUtils to escape and unescape html. I have following code import org.apache.commons.lang.StringEscapeUtils; public class EscapeUtils { public static void main(String args[]) { String string = " 4-Spaces …
Bilal Mirza
  • 2,576
  • 4
  • 30
  • 57
3
votes
1 answer

Escape characters when generating Powershell scripts using C#

I use VS2010, C#, .NET 3.5 for generate Powershell scripts (ps1 files). Then, it is required escape characters for Powershell. Any suggestions about it for develop good method that escape characters? public static partial class StringExtensions …
Kiquenet
  • 14,494
  • 35
  • 148
  • 243
2
votes
0 answers

Excluding “ when using StringEscapeUtils.escapeHtml4

I am trying to Sanitize the requestBody. For this purpose I am converting Object to Json and then passing the Json to requestBody { "data": { "id": "123", "unit_id": "456", "country": "jp", …
2
votes
0 answers

Bug in apache commons-text 1.2 StringEscapeUtils.unescapeJson

unescapeJson seems to do nothing in 1.2 - It worked correctly in commons-lang3 3.6 The unit tests in the package seem weird to me: @Test public void testUnescapeJson() { final String jsonString = …
ModdyFire
  • 706
  • 3
  • 9
  • 19
2
votes
2 answers

Node.js spawn 'echo $(python --version)'

I want to use node.js to spawn echo $(python --version), if I put this into my terminal it works no problem, I get something like Python 2.7.12 But if I use the following code: var spawn = require('child_process').spawn var child = spawn('echo',…
Eoin Murray
  • 1,935
  • 3
  • 22
  • 34
2
votes
1 answer

Javac not registering class path and methods correctly, symbol not found

I'm trying to use Apache Commons StringEscapeUtils. I've got this line of code in my import statement, import org.apache.commons.lang3.StringEscapeUtils; I've downloaded apache commons lang, extracted it and moved: commons-lang3-3.4.jar (Note:…
user5353256
2
votes
2 answers

Java -> Apache Commons StringEscapeUtils -> escapeJavaScript

For a very simple ajax name lookup, I'm sending an id from the client webpage to the server (Tomcat 5.5, Java 5), looking it up in a database and returning a string, which is assigned to a javascript variable back in the client (and then…
Ignacio
1
vote
3 answers

Replace directory path by manipulating string - Java

How do i replace the directory path of a string? The original string is: String fn = "/foo/bar/ness/foo-bar/nessbar.txt"; i need the output to look like: /media/Transcend/foo-bar/nessbar.txt I've tried the line below but it doesn't work…
alvas
  • 115,346
  • 109
  • 446
  • 738
1
vote
0 answers

How can I escape from special character using stringutils substring with a given length JAVA

Is there any way to add a special character using a substring with a given length? String example= "abcde & fghijk"; System.out.printLn("(StringUtils.substring(StringEscapeUtils.escapeXml(example)),0,12)); current output("abcde & f") expected…
newbird
  • 39
  • 1
  • 4
1
2 3 4 5 6