When I hit the page /login?email=abc+dev#xyz.com
In Ruby's Controller,
The Parameters are: {"email"=>"abc dev#xyz.com"}
+ is missing in this parmas.
What is the correct way to get email in parameters ?
encode URI will give me same(that is, URI::encode("abc+dev#xyz.com") is equals to "abc+dev#xyz.com")
You can use Rack::Utils.escape()
Rack::Utils.escape("abc+dev#xyz.com")
# => "abc%2Bdev%40xyz.com"
Or with Javascript you can use encodeURIComponent()
encodeURIComponent("abc+dev#xyz.com")
"abc%2Bdev%40xyz.com"
Related
I wanted to navigate to a URL using queryParams while Routing in Angular.
<a routerLink='/master' [queryParams]="{query:'%US',mode:'text'}"><li (click)="search()">Search</li></a>
The URL I wanted to navigate is:
http://localhost:4200/master?query=%US&mode=text
But when I click on search it navigates me to:
http://localhost:4200/master?query=%25US&mode=text
I do not know why 25 is appended after the % symbol. Can anyone tell me a cleaner way to navigate correctly.
In URLs, the percent sign has special meaning and is used to encode special characters. For example, = is encoded as %3D.
Certain special characters are not allowed in url. If you want to use those in url you have to encode them using encodeURIComponent javascript function.
%25 is actually encoded version of % character. Here browser is encoding them itself.
When trying to get queryParams from url , you can decode them using decodeURIComponent.
For more information check : https://support.microsoft.com/en-in/help/969869/certain-special-characters-are-not-allowed-in-the-url-entered-into-the
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/decodeURIComponent
When submitting form using get method if we pass # character in any field it skips all parameter after that field.
e.g.
bookmy_car.php?pod=6&room_id=32&starthour=14&startminute=00&startday=07&startmonth=08&startyear=2015&endhour=16&endminute=00&endday=07&endmonth=08&endyear=2015&end_date=1438927200&email_conf=1&cost_code=&desc=Trip description&trip_comment=#&day_rate=68.00&hourly_rate=6.60&hourly_km_rate=0.35&dur_hours=2
hours&location_charge=0.00&damage_cover_charge=5.00&total_free_kms=&longterm=0&rt=&minbooking=3600&returl=&returl_newid=&rep_id=&edit_type=&insPlanid=3&plan_name=goOccasional&id=3&driver_username_id=2&
How do we protect it? I tried escape() and encodeURI() function of JavaScript, it does not help.
I agree with #dgsq . But i prefer using only encodeURI so that he can get the uri as it is in the next page.
alert( encodeURI('&trip_comment=#&day_rate=68.00') )
It happens because with hashbang in query string # it is interpreted as location.hash and hot processed as GET parameters. You need to properly encode URI before you use it. For example with encodeURIComponent:
alert( encodeURIComponent('trip_comment=#') )
My url contains a special character '/'.Example :- localhost:8080/name=asdasd 11/2/2015. When I pass this through encodeURI to the spring framework , I need to differentiate '/' which is present in my variable and the one which is the actual separator. I have tried using './*' which returns me the string after the seperator but in case I have two args in my url which contain '/' then the above solution fails. How do I solve this ??
Are you looking for like this. Encode it only values.
var myUrl ='localhost:8080/name=' + encodeURIComponent('asdasd 11/2/2015');
I would like to know how I can escape / in angularjs so that I can send it as a path variable to call a restful service. As of now I am getting 404 whenever I try to send a url with path variable values having /; even if I encode it doesn't work.
For example
http://monish.home.com/payment/9a2c1ae67d4ff85e561679fcff/credit/%252B8VMWj/YBC%252FNj3l/fetch/options
Is there a way where I can encode and escape the /?
Yes, its called encodeURIComponent
var a = 'http://monish.home.com/payment/9a2c1ae67d4ff85e561679fcff/credit/%252B8VMWj/YBC%252FNj3l/fetch/options'
encodeURIComponent(a); // result: "http%3A%2F%2Fmonish.home.com%2Fpayment%2F9a2c1ae67d4ff85e561679fcff%2Fcredit%2F%25252B8VMWj%2FYBC%25252FNj3l%2Ffetch%2Foptions"
In some project I've met these lines:
$.get("defaults/data.json?", ...);
$.get("defaults/structure.html?", ...);
$.get("defaults/style.css?", ...);
On server side these files without any extra symbols, so
I'm wondering what does the question mark at the end of files mean?
The ? in a URL denotes the start of the query string. A ? at the end with no variables following it is usually an unnecessary way of saying "this has absolutely no querystring".
It would be possible with a URL rewriting engine for example, to examine the incoming REQUEST_URI to see if it ends with ? and take a different action than requests not ending in ?, but that would be an unusual usage. It would much more common to just specify some value in the query string.
"?" is the separator for supplying arguments via a GET request.
? states you're providing arguments via HTTP GET.
For example if you want to send a=1 and b=2 , you would do http://mysite.com/myfile.php?a=1&b=2
Shai.