Friday, October 31, 2008

A hack too far

I was just looking at the PackUriHelper class, with a view to implementing it in Mono. One of it's many methods converts a regular Uri into a 'pack' Uri. For example:

http://www.test.com/main/page.html?query=val#middle
converts to
pack://http:,www.test.com,main,page.html?query=val#middle/

So I says to myself, this is easy, it's just combining two Uris. Simple!

Wrong

Uri original = new Uri ("http://www.test.com/main/page.html?query=val#middle");

Uri complete = new Uri ("pack://" + original.OriginalString); // FAILS
Uri complete = new Uri (new Uri ("pack://", original)); //FAILS
Uri complete = new Uri (new Uri ("pack://", original.OriginalString)); // FAILS

How about escaping the second string...
string escaped = Uri.HexEscape (original.OriginalString);
Uri complete = new Uri ("pack://" + escaped); // FAILS

So at this stage I've lost all faith in humanity, so i try a basic test just to make sure i'm not insane. I'll try create a pack uri object myself, just to prove that it really is possible to parse them.

Uri complete = new Uri ("pack://http:,www.test.com,main,page.html?query=val#middle/");

EPIC FAIL

You can't do that. While they can *generate* that Uri for you, you can't generate one for yourself. Funnily enough, they do register a custom parser for the pack scheme, it's just incapable of parsing pack URI's. Don't ask me why.

After several hours and a lot of wasted time I finally came up with this:

Uri complete = new Uri (new Uri ("pack://"), escaped);

This is the *only* way to create a Pack URI. You have to hex escape the original uri and then call the constructor overload which takes a Uri and a string.

That is one of the stupidest things I've ever seen.

1 comment:

梁爵 said...

2020.03.20八大行業酒店上班因武漢肺炎 (COVID-19) 疫情持續延燒,對酒店工作帶來衝擊,據酒店打工數據組織 (酒店PT) 的數據顯示,因疫情造成的經濟和酒店S危機,恐將使不少酒店小姐失業人數上升至近10萬人。
酒店S模擬了最壞的情況,若今年酒店經紀成長率下跌7個百分點,則失業人數可能暴增至3萬,超越 2009 年八大行業危機時期失業人數10萬人。
由於疫情爆發帶來的經濟後果轉化為工作時間和工資的減少,預期失業人數恐將持續增加。就業率的下降也意味著工人的大量收入損失。該研究估計,到 2020 年底,收入損失將在 8600 萬至 1億元之間,也將使得酒店S和服務的消費支出下降,進而影響飯局和援交前景。

Hit Counter