Angular2 router link with JSON parameter - angular2-routing

I have an angular2 application and I'm, having trouble with the back button.
I have a router link with a queryString paramater. The parameter (named filter) has a value that's a JSON.
I have a router link defined as follows:
<a [routerLink]="['/app/listing', {filter: getFilter(model.id)}]">{{model.count}}</a>
The getFilter method does this:
getFilter(id) {
return JSON.stringify({ Country: [id] });
}
That returns as expression like this:
"{"Country":[9]}"
I want a querystring like this.
http://localhost:54675/app/listing?filter={"Country":[6]}
This is what Angular assemblies:
http://localhost:54675/app/listing;filter=%7B%22Country%22:[6]%7D
URL Encoding changed the quotes and brackets. I don't fully understand why the ? was replaced with ;.
This works fine and the listing page processes the filter. However, if I drill down and then go back I get this error when calling JSON.Parse on the filter:
Unexpected token % in JSON at position 0
When I first go to the page using the router link the filter value is:
"{"Country":[6]}"
But when I use back the filter value is:
"%7B%22Country%22:[6]%7D"

Related

Uri.https on Flutter is limiting the length of my url

I'm trying to make a get request to Firebase. In my url, I have to send the auth token which is very long (more than 900 characters). I create the url this way:
var url =
Uri.https('firebaseio.com', '/mydb.json?auth=$authToken&orderBy="userId"&equalTo="$userId');
But the url is not complete when I print it (the last characters are always lacking) and hence the request does not work. Anyone knows a solution for that?
Your URL isn't actually being cut. The print function can have a limit on its line length when being using in Flutter. Look elsewhere for your issue.
It likely has something to do with your misuse of quotes within your string. It's not normal to have quotes in your query parameters that are opened but not closed.
You can also improve this code by using the optional third queryParameters parameter of the Uri.https constructor to handle your query parameters:
var url = Uri.https(
'firebaseio.com',
'/mydb.json',
{
'auth': authToken,
'orderBy': '"userId"',
'equalTo': '"$userId"',
},
);

How can I get custom querystring included in returned firebase dynamic shortlink

I'm using the Firebase dynamic link post API to return a shortlink. When I post this:
https://CENSORED.page.link/?link=https://www.CENSORED.co.uk/offers/friends/?utm_source=referafriend&utm_medium=ecrm&utm_campaign=cbk25&utm_term=988776
clicking the returned shortlink redirects to:
https://www.CENSORED.co.uk/offers/friends/?utm_source=referafriend
The post is made from clientside js. Firebase is returning a working shortlink, but with some parameters missing.
Expected url from clicked shortlink:
https://www.CENSORED.co.uk/offers/friends/?utm_source=referafriend&utm_medium=ecrm&utm_campaign=cbk25&utm_term=988776
Looks like its chopping off most of my querystring - how do I get the full query string returned correctly please?
Solved: Escaping the url worked for me:
params lost:
"https://www.test.co.uk/testing/?utm_source=jam&utm_medium=spoon&utm_campaign=jar&utm_term=lid"
params returned correctly:
"https%3A%2F%2Fwww.test.co.uk%2Ftesting%2F%3Futm_source%3Djam%26utm_medium%3Dspoon%26utm_campaign%3Djar%26utm_term%3Dlid"

Wordpress - How to Pass request value via URL

I am trying to pass a parameter to a wordpress page. I don't want to pass it as a query string. I would like to pass as a slash based url.
Example
http://localhost/mysite/city?des=tn
To
http://localhost/mysite/city/tn
You'll have to use a custom query var and add a rewrite rule.
See this question and the answer for an example.
"To be added on init" means you should put this in an action hook that runs on the init event, like so
function addCityVar() {
// ....
}
add_action("init", "addCityVar");

FlowRouter query parameter parsing is wrong

When I tried to parse this URL:
http://localhost:3000/torrent?previous=%2Ftorrent%3Fprevious%3D%252Fuser%26route%3D&route=torrent-item
I was expecting route = 'torrent-item' (String), but FlowRouter router value is ["", "torrent-item"] (Array)
online - https://ts-vcompile.herokuapp.com/user#!/torrent?previous=%2Ftorrent%3Fprevious%3D%252Fuser%26route%3D&route=torrent-item
repo - https://github.com/HedCET/TorrentSearch
There is one key route in queryparameter which has no value. So default value assumed is an empty string. It will always return you an array of keys with same name(in this case 'route').
So you will not get route = 'torrent-item'
previous=%2Ftorrent%3Fprevious%3D%252Fuser%26route%3D&route=torrent-item
Your URL decodes as
http://localhost:3000/torrent?previous=/torrent?previous=%2Fuser&route=&route=torrent-item
cf: http://meyerweb.com/eric/tools/dencoder/
so you have &route=&route=torrent-item which will return ["", "torrent-item"] since route is there twice.
You just need to figure how to encode this URL properly to read it right.
If it's a URL you are reading from somewhere, then you need to parse the multiple arguments of the array to find what you want.

jQuery ajax call containing script-tag in data

I read some values from text boxes and send them via jQuerys post method to an server. If the user enters text containing something like "bla bla", the call fails. The data looks like this in that case:
var data = { myKey: 'bla <script> bla' };
And I send it to the server like this:
$.post(targetUrl, data, function(x) {...});
On the server side (an Asp.Net web form) it looks like the call never reaches the server. Any hint how to solve that? If there's a convenient function which cleans data from bad tags, that would be fine too.
Have you desactivate the validate request of your aspx page?
add this in your page declaration: validateRequest="false"
To strip tags using a jQuery function:
jQuery.fn.stripTags = function() {
return this.replaceWith( this.html().replace(/<\/?[^>]+>/gi, '') );
};
Do you receive a page_load in ASP.NET? If yes, isn't there anything in Request.Params?
I would suggest escaping your values client side using the javascript escape function as shown below
var data = { myKey: escape('bla <script> bla') };
Once you have done that, you can retrieve the correct value on the server side using the following (.Net Code)
HttpUtility.UrlDecode(param_value_to_decode)
I tested this and the correct value is being passed correctly to the server via the post request.
Hope this helps.
Additional Info : I forgot to mention the cause of the error. When inspecting the request using firebug, it returns a "500 Internal Server Error - A potentially dangerous Request.Form value was detected from...". This is a built in protection mechanism from asp.net to protect against script injection. The following page directive ValidateRequest="false" did not solve the problem as expected (Works in traditional WebForms). It might be something specific to the Mvc platform, not to sure. The above solution does work, so just use that.
Regards
G

Resources