Fixed issue where empty query is attached to publish URLs

Please review, not sure if this has any effect on other functionality.

Also, the entire filtering looks a bit weird to me, with all the `rawurldecode` (shouldn't that be `rawurlencode` ?) and `&amp;` replacing.