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

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

Related

Getting string from another string in Javascript [duplicate]

This question already has answers here:
Parse JSON in JavaScript? [duplicate]
(16 answers)
Closed 2 years ago.
Please note that this is not a json object :) My string is:
{"message":"***error in SAP module:-1***","status":400}
This is not a json object, this is a pure string. I cannot turn it into a json object due to technical limitations.
So, I want to take only the bold string (all the value of "message").
I thought about lastIndexOf, and pick the string between ":" and ","
But I got messed up with the escape characters for the quotes.
How can I achieve it with lastIndexOf? Or in another better way?
If you can't use JSON.parse, I would use a regex to read it. You know you want the string directly following "message":", so I would look for that, then grab everything from there to the next occurrence of "

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

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".

regex to retrieve specific url from text [duplicate]

This question already has answers here:
Regular Expression to find a string included between two characters while EXCLUDING the delimiters
(13 answers)
Closed 7 years ago.
An API I use returns this text:
<http://192.168.1.10:8080/longUrl>; rel="recording-session",
<http://192.168.1.10:8080/realLongUrl>; rel="h264-session-sdp",
<http://192.168.1.10:8080/realLongDifferentUrl>; rel="h264-session-sdp",
<rtp://239.1.1.18:5006>; rel="destination-high",
<rtp://239.1.1.17:5006>; rel="destination-low"
I'm trying to retrieve the first URL that is followed by ; rel="h264-session-sdp.
So in this case that would be: http://192.168.1.10:8080/realLongUrl
I've been fiddling around trying to modify examples found here on SO, but just can's seem to get it right.
try this one /([^<]+)(?:>; rel\=\"h264\-session\-sdp\")/
Selects the text inbetween the greater then and less then characters:
?<=\<)(.*?)(?=>)
https://regex101.com/r/oS5sX6/1
And if you wanted to select the urls on multiple lines, add the g and m modifiers:
/(?<=\<)(.*?)(?=>)/gm
https://regex101.com/r/oS5sX6/2
Try this:
/(?<=\<)(.*?)(?=\>)>; rel="h264-session-sdp"/

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');

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