whatsapp://send?text cut string from '&' character till end? [duplicate] - javascript

This question already has answers here:
Escaping ampersand in URL
(8 answers)
Closed 6 years ago.
I'm trying to add a link that can be shared in WhatsApp:
For example:
"whatsapp://send?text=http://www.example.com/products/women/dresses?sessionid=34567&source=google.com"
But the link that is sent in WhatsApp is truncated from the '&' until the end. (the second parameter)
The same thing happens when I try:
"WhatsApp://send?text=http://www.example.com/prod&ucts/"
(note the '&' in the middle of the word 'prod&ucts')
The text after the '&' is truncated.
Any suggestions why this is happening and how can I fix it?

It'll be cutting it off because an '&' denotes a new query string parameter. You can fix it by encoding the string parameter in your URL using the encodeURI JavaScript function. The & character will encode to "%26".

Related

can '?' separator be included twice in the URL [duplicate]

This question already has answers here:
Is it valid to have more than one question mark in a URL?
(2 answers)
Closed 1 year ago.
https://www.websitename.com/?audience=testingting?internal-abhishek-jwt=random_string
Is this a valid URL? i.e is it fine to have two '?' separators in the URL?
Note: Due to limitations, I can not add '&' to internal-abhishek-jwt=random_string
It isn't. You have to URL encode the second one if you want to use it as a parameter or use '&' symbol instead if you wanna separate your arguments (which seems to be the case here).
Some further explanation here
The ? still indicates the start of the query string.
Segments of the query string are separated by & characters.
This will be parsed as:
key: audience
value: testingting?internal-abhishek-jwt=random_string

Regex find url with specefic character inside (js) [duplicate]

This question already has answers here:
Regular expression to stop at first match
(9 answers)
Closed 1 year ago.
I have the following text:
Some text
{\"url\": \"https:\/\/www.someurl.com\/200x200\/fsdffsde3e", \"bbb\"} kljkl
{\"url\": \"https:\/\/www.someurl.com\/500x500\/fsdffsde3e", \"bbb\"} kljkl
Some text
I want to extract all the URLs contains 200x200. so for example I need this URL: https:\/\/www.someurl.com\/200x200\/fsdffsde3e
this, will bring the entire row: "https(.*?)200x200(.*)" but I want only the URL.
Have a look: https://regex101.com/r/DDWLDM/1
Thanks
use This exp
"https(.*?)200x200(.*?)"

Replace parentheses in URL strings [duplicate]

This question already has answers here:
Passing "(" and ")" through a URI causes a 403 error, how can I encode them?
(2 answers)
Closed 1 year ago.
I have string with URL links like below. But urls are breaking when urls have parenthesis like below. The urls are breaking at the start of parenthesis in URL.
This is test http://ang.wikipedia.org/wiki/Wikipedia:Tutorial_(Wikipedia_links)
Can we replace parentheses with other ASCII characters using javascript regex?
Use the string.replace() method.
url = url.replace(/\(/g, '%28').replace(/\)/g, '%29');

Parsing JSON containing new line characters [duplicate]

This question already has answers here:
How do I handle newlines in JSON?
(10 answers)
Closed 8 years ago.
In my website I try to convert a string to JSON which contains a newline.
JSON.parse('{"hallo":"line1\r\nline2","a":[5.5,5.6,5.7]}');
This produces an "Unexpected token" error. Do I need to escape that somehow?
Yes, you should escape both \n and \r as they belong to the list of control characters. Full list of characters that need to be escaped can be found here. Your code would be
obj = JSON.parse('{"hallo":"line1\\r\\nline2","a":[5.5,5.6,5.7]}');
JSFiddle: link
Try:
JSON.parse('{"hallo":"line1\\r\\nline2","a":[5.5,5.6,5.7]}');

Using ‘&’ in POST variables [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
ajax post special characters
I am building my own post parameters and passing them via ajax; however, my POST contains an & symbol. How can I post these and escape the special characters so it posts as text only and doesn't split up my value?
Ex:
Thing=lala&lalala
Should be thing = 'lala&lalala' but what I get is thing = 'lala' and ='lalala' where the second key is blank.
You should use encodeURIComponent on your parameters before sending them to the server. It will properly escape everything in your parameters.
Quick example:
var s = 'Thing=' + encodeURIComponent('lala&lalala');
Please note that every value should be encoded separately (so you should not simply use it on the whole query string).

Categories