Silverlight: URL parameter in query string escaped - silverlight

in Silverlight 5:
var uri= new Uri("http://www.last.fm/api/auth/?api_key=xyz&cb=http://localhost:19000/callback?bla=blu")
HtmlPage.Window.Navigate(uri);
lands my browser at:
http://www.last.fm/api/auth?api_key=xyz&cb=http://localhost:19000/callback%253Fbla=blu
Note how the "?" of the URL in the callback parameter gets escaped to %253F - even though, if I look at uri.ToString() in the debugger, it's not escaped.
How can I prevent that from happening?
Many thanks,
Max

I got no answer, but if anyone stumbles across the same issue, here's what I tried and what I finally did:
First, I attempted to use HtmlPage.Window.Eval() to execute javascript which would navigate to that URL. Again, the ? was escaped even though URL.ToString() didn't escape it.
So what I finally did - could have thought of it earlier, really ;P - was to change my callback handler to follow a REST like format. Instead of:
http://localhost:19000/callback?bla=blu
it now listens at:
http://localhost:19000/callback/bla=blu
and takes the parameter value out of the path. No question mark involved anymore, problem solved.

Related

Regex for graphQl not returning results when added to react component

I was testing queries out with GraphiQl explorer, which returned the results I wanted using the a regular expression underlined in red below.
You can see it returns results and it generates the code for react in the far right of the screenshot. I was hopeful that it would work straight away with a copy & paste but apparently you have to escape the regex in the template literal string (Why doesn't the code explorer do that if you need to escape it anyway?)
Below are the results if you try to add the code the way its generated.
Through some googling & a GitHub issue I found that the regex needs to be double escaped.
See the update for the fix below. Link to regex PR
Added the change to my regex and it stopped the previous error.
But now its not showing any results..
Regex updated ->
No results ->
I've tried using variables to inject the original regex to the template literal string but no avail as apparently you can't do that with graphQl. Has anyone had this issue or care to share an idea/solution ?

How to use $header in routes

I'm creating a route using the Java DSL in Camel.
I'd like to perform a text substitution without creating a new processor or bean.
I have this:
.setHeader(MY_THING,
constant(my_template.replace("{id1}", simple("${header.subs_val}").getText())))
If I don't add 'constant' I get type mismatch errors. If I don't put getText() on the simple() part, I get text mismatch answers. When I run my route, it replaces {id} with the literal ${header.subs_val} instead of fetching my value from the header. Yet if I take the quotes off, I get compile errors; Java doesn't know the ${...} syntax of course.
Deployment takes a few minutes, so experiments are expensive.
So, how can I just do a simple substitution. Nothing I am finding on the web actually seems to work.
EDIT - what is the template? Specifically, a string (it's a URL)
http://this/that/{id1}/another/thing
I've inherited some code, so I am unable to simply to(...) the URL and apply the special .tof() (??) formatting.
Interesting case!
If you place my_template in a header you could use a nested simple expression(Camel 2.9 onwards) like in the example below. I am also setting a value to subs_val for the example, but I suppose your header has already a value in the route.
.setHeader("my_template", constant("http://this/that/{id1}/another/thing"))
.setHeader("subs_val",constant("22"))
.setHeader("MY_THING",simple("${in.header.my_template.replaceAll(\"\\{id1.?\",${in.header.subs_val.toString()})}"))
After this step header MY_THING has the value http://this/that/22/another/thing.
1)In this example I could skip to_String() but I do not know what's the type of your header "subs_val" .
2) I tried first with replaceAll(\"\{id1\"}\") but it didn't work with } Probably this is a bug...Will look at it again. That's why in my regex I used .?
3) When you debug your application inside a processor, where the exchange is available you can use SimpleBuilder to evaluate a simple expression easily in your IDE, without having to restart your app
SimpleBuilder.simple("${in.header.url.replaceAll(\"\\{id1.?\",${in.header.subs_val.toString()})}").evaluate(exchange, String.class);
Hope it helped :)

HTMLPurifier: how to escape broken tags instead of removing?

I am using HTMLPurifier for cleaning the post input but I'd like it to escape (html encode) all broken tags or suspicious symbols instead of removing them completely. I have searched through it's docs and this site but without any luck. Still hope that I have missed something.
Opening tag is the most irritating. If someone tries to post a formula or comparison, writes "param1<param2" and does not put space in between, the purifier gets it as a wrong tag opening and completely discards everything on the right side.
I am using htmlspecialchars inside [code] tags, but I want to allow some html outside and cannot encode everything.. That is why I'm filtering it with HTMLPurifier.
Your advice would be appreciated.
Try %Core.AggressivelyFixLt or using %Core.LexerImpl set to DirectLex. I don't know offhand if this will work, it may not.
A partial solution is to set %Core.EscapeInvalidTags; but it's a pretty imperfect fix, and it may mangle some text.

phpQuery behaving weird, changing HTML

I want to process a template with a Google plusone button in it through phpQuery and I run into the following problem:
require_once( "phpQuery.php" );
$p = phpQuery( "<g:plusone></g:plusone>" );
echo $p->html();
the expected output would be:
<g:plusone></g:plusone>
But instead the output of this is:
<plusone></plusone>
Which doesn't match up with what google is expecting, so the button doesn't work any more. How can I stop phpQuery from changing (fixing?) my code, or how can I work around this problem without changing the string from plusone to g:plusone once the processing is done? (that's a nasty workaround, plus, I run into more of these 'translation'-problems in phpQuery).
I had the same problem while including a google+ badge. I could force the code generator from google to generate code with a div container. I just had to tick the "html5 valid code" checkbox.
I've been looking all over for solutions for this problem, to no avail. I found a horrible workaround. I'm sure this is NOT the most elegant way to do this, but at least it fixes the problem.
Instead of the tags:
<g:plusone>...</g:plusone>
use:
<g__0058__plusone>...</g__0058__plusone>
Then simply str_replace the result before you're outputting:
echo str_replace("__0058__",":",$doc->html());
Basically in a tag where you would normally put a colon (:) you put 0058 instead. It's a very non-elegant solution, I realise that, but at least it's a workaround to this old problem.

Backslashes in secondary tiles URI getting turned into forward slash - WP7

Hi I got this really irritating problem and I'd like to know if there is some way around it.
The thing is, the secondary tiles I am creating have an URI with a parameter being a path (with backslashes). However, whenever I try to query the active tiles, the path parameter has all its backslashes converted into forward slashes...
Is there another way around this than just replacing all my back slashes by forward slashes?
Thanks!
Can we see your code? Im guessing something is being escaped incorrectly but without an example its hard to tell.

Resources