question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to allow character '&' without convert to '&'

See original GitHub issue

i have data from http post data like this :

"billingCode=820131114000031&custName=Josh & Mark&numAccount=25800&parameterId=2&traceId=820131114000031"

if i use jsoup :

String postDataori = Jsoup.clean("billingCode=820131114000031&custName=Josh & Mark&numAccount=25800&parameterId=2&traceId=820131114000031", Whitelist.basic());
System.out.println("PostData  : " + postDataori);

and the output like this :

PostData  : billingCode=820131114000031&custName=Josh & Mark&numAccount=25800&parameterId=2&traceId=820131114000031

my question is how to allow character ‘&’ without convert to & ?

Issue Analytics

  • State:closed
  • Created 10 years ago
  • Comments:20 (5 by maintainers)

github_iconTop GitHub Comments

3reactions
isapircommented, Feb 7, 2017

@cketti My issue is not with Parsing; It’s with rendering of the HTML when calling Document’s toString() or html().

As I wrote above, I need to render links that work, so the delimiter of the Query String is a single & symbol, and not an HTML entity, e.g. https://www.google.com/search?source=hp&q=jsoup

But JSoup always produces the delimiter as HTML entities, which leads to broken links, e.g. https://www.google.com/search?source=hp&q=jsoup

There has to be a way to render the HTML with single &. This issue has affected many others judging by the mailing list and StackOverflow, and they resorted to doing something like:

String htmlString = doc.toString().replace("&", "&");

The best solution IMO is to add another EscapeMode that will be more permissive, and will not enforce entities where they are not needed nor desired.

2reactions
mjclementecommented, Feb 24, 2017

Hahaha. True. I fully acknowledge that. Which is why I was hoping Jsoup would have an option to allow valid ampersands to remain unencoded. But if that’s not gonna happen, at least my hacky code is getting the job done 👍

Read more comments on GitHub >

github_iconTop Results From Across the Web

Java String Replace '&' with & but not & to &amp
I want to replace all the occurrences of & character to & While replacing this, I also need to make sure that I...
Read more >
Generating XML without converting '&' to 'amp;' - Ask TOM
Hi Tom, do you know of anyway of utilising the XDK to generate XML without certain characters being displayed as HTML entities.
Read more >
PHP htmlspecialchars_decode() Function - W3Schools
Definition and Usage. The htmlspecialchars_decode() function converts some predefined HTML entities to characters. HTML entities that will be decoded are:.
Read more >
MATLAB convertCharsToStrings - MathWorks
Convert character arrays to string arrays, leaving other arrays unaltered ... you can use convertCharsToStrings to make your code accept character arrays.
Read more >
Conversion Functions | Alteryx Help
Conversion functions can be used with String and Number data types. ... that cannot be used to represent a character may give a...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found