Issue with Encoding "&" in Urls

URL encode sees “&” (ampersand) as “&” HTML entity

Without seeing your code, it's hard to answer other than a stab in the dark. I would guess that the string you're passing to encodeURIComponent(), which is the correct method to use, is coming from the result of accessing the innerHTML property. The solution is to get the innerText/textContent property value instead:

var str, 
el = document.getElementById("myUrl");

if ("textContent" in el)
str = encodeURIComponent(el.textContent);
else
str = encodeURIComponent(el.innerText);

If that isn't the case, you can usethe replace() method to replace the HTML entity:

encodeURIComponent(str.replace(/&/g, "&"));

Escaping ampersand in URL

They need to be percent-encoded:

> encodeURIComponent('&')
"%26"

So in your case, the URL would look like:

http://www.mysite.com?candy_name=M%26M

Url encoding issue with url connection

If you only have the URL, use this method

private String encodeUrl(String link) throws UnsupportedEncodingException {
Uri uri = (Uri.parse(link));
String result = null;
if (Objects.equals(uri.getScheme(), "content")) {
try (Cursor cursor = getContentResolver().query(uri, null, null, null, null)) {
if (cursor != null && cursor.moveToFirst()) {
result = cursor.getString(cursor.getColumnIndex(OpenableColumns.DISPLAY_NAME));
}
}
}
if (result == null) {
result = uri.getPath();
int cut = Objects.requireNonNull(result).lastIndexOf('/');
if (cut != -1) {
result = result.substring(cut + 1);
}
}
return link.replace(result
,URLEncoder.encode(result, "UTF-8")
.replace("+", "%20"));
}

Possible URL encoding issues

You should probably escape spaces as %20 in the range_from and range_to params. I don't know how to do that in Ruby, but this question looks like a good start.

The browser probably escapes URLs automatically, which is why you get correct answers there.

URL Encoding issue in swift ios

Your URL is already percent-encoded.

If you encode it again, the percent parts will be encoded twice, giving an invalid URL.

You can see that by removing the percent encoding from your URL and setting it again:

let base = "https://baseURL/The+Man+in+the+High+Castle+Official+Trailer+%E2%80%93+2+th.m3u8"
let decoded = base.stringByRemovingPercentEncoding!
print(decoded)
let encoded = decoded.stringByAddingPercentEncodingWithAllowedCharacters(NSCharacterSet.URLFragmentAllowedCharacterSet())!
print(encoded)

Nginx URL Encoding Issue

I managed to solve the issue by doing this.

If there is a better way to handle this, please let me know.

location ~* /forum/index.php(.*)
{
include /nginx/proxypass.conf;
if ($args) {
proxy_pass http://127.0.0.1:80/forum/index.php?$args;
}
proxy_pass http://127.0.0.1:80/forum/index.php$1;
}


Related Topics



Leave a reply



Submit