Commit 96f196fe authored by Hubzilla's avatar Hubzilla

add gen_link_id() function to selectively encode/decode the message-id...

add gen_link_id() function to selectively encode/decode the message-id component of /display/ links for message-ids that contain troublesome characters
parent 5ce96b9b
......@@ -409,7 +409,7 @@ class ThreadItem {
'comment' => $this->get_comment_box($indent),
'previewing' => ($conv->is_preview() ? ' preview ' : ''),
'wait' => t('Please wait'),
'submid' => substr($item['mid'],0,32),
'submid' => base64_encode(substr($item['mid'],0,32)),
'thread_level' => $thread_level
);
......
......@@ -30,12 +30,10 @@ class Display extends \Zotlabs\Web\Controller {
if(argc() > 1 && argv(1) !== 'load')
$item_hash = argv(1);
if($_REQUEST['mid'])
$item_hash = $_REQUEST['mid'];
if(! $item_hash) {
if(! $item_hash) {
\App::$error = 404;
notice( t('Item not found.') . EOL);
return;
......@@ -93,9 +91,15 @@ class Display extends \Zotlabs\Web\Controller {
// find a copy of the item somewhere
$target_item = null;
if(strpos($item_hash,'b64.') === 0)
$decoded = @base64url_decode(substr($item_hash,4));
if($decoded)
$item_hash = $decoded;
$r = q("select id, uid, mid, parent_mid, item_type, item_deleted from item where mid like '%s' limit 1",
dbesc($item_hash . '%')
dbesc($item_hash . '%'),
dbesc($decoded . '%')
);
if($r) {
......
......@@ -724,6 +724,8 @@ class Item extends \Zotlabs\Web\Controller {
if(! $mid) {
$mid = (($message_id) ? $message_id : item_message_id());
}
if(! $parent_mid) {
$parent_mid = $mid;
}
......@@ -935,7 +937,7 @@ class Item extends \Zotlabs\Web\Controller {
'from_xchan' => $datarray['author_xchan'],
'to_xchan' => $datarray['owner_xchan'],
'item' => $datarray,
'link' => z_root() . '/display/' . urlencode($datarray['mid']),
'link' => z_root() . '/display/' . gen_link_id($datarray['mid']),
'verb' => ACTIVITY_POST,
'otype' => 'item',
'parent' => $parent,
......@@ -953,7 +955,7 @@ class Item extends \Zotlabs\Web\Controller {
'from_xchan' => $datarray['author_xchan'],
'to_xchan' => $datarray['owner_xchan'],
'item' => $datarray,
'link' => z_root() . '/display/' . urlencode($datarray['mid']),
'link' => z_root() . '/display/' . gen_link_id($datarray['mid']),
'verb' => ACTIVITY_POST,
'otype' => 'item'
));
......@@ -1005,7 +1007,7 @@ class Item extends \Zotlabs\Web\Controller {
}
$datarray['id'] = $post_id;
$datarray['llink'] = z_root() . '/display/' . urlencode($datarray['mid']);
$datarray['llink'] = z_root() . '/display/' . gen_link_id($datarray['mid']);
call_hooks('post_local_end', $datarray);
......
......@@ -447,7 +447,7 @@ class Like extends \Zotlabs\Web\Controller {
$arr['thr_parent'] = $item['mid'];
$ulink = '[zrl=' . $item_author['xchan_url'] . ']' . $item_author['xchan_name'] . '[/zrl]';
$alink = '[zrl=' . $observer['xchan_url'] . ']' . $observer['xchan_name'] . '[/zrl]';
$plink = '[zrl=' . z_root() . '/display/' . urlencode($item['mid']) . ']' . $post_type . '[/zrl]';
$plink = '[zrl=' . z_root() . '/display/' . gen_link_id($item['mid']) . ']' . $post_type . '[/zrl]';
$allow_cid = $item['allow_cid'];
$allow_gid = $item['allow_gid'];
$deny_cid = $item['deny_cid'];
......
......@@ -138,7 +138,7 @@ class Subthread extends \Zotlabs\Web\Controller {
$ulink = '[zrl=' . $item_author['xchan_url'] . ']' . $item_author['xchan_name'] . '[/zrl]';
$alink = '[zrl=' . $observer['xchan_url'] . ']' . $observer['xchan_name'] . '[/zrl]';
$plink = '[zrl=' . z_root() . '/display/' . urlencode($item['mid']) . ']' . $post_type . '[/zrl]';
$plink = '[zrl=' . z_root() . '/display/' . gen_link_id($item['mid']) . ']' . $post_type . '[/zrl]';
$arr['body'] = sprintf( $bodyverb, $alink, $ulink, $plink );
......
......@@ -60,7 +60,7 @@ class Tagger extends \Zotlabs\Web\Controller {
$links = array(array('rel' => 'alternate','type' => 'text/html',
'href' => z_root() . '/display/' . urlencode($item['mid'])));
'href' => z_root() . '/display/' . gen_link_id($item['mid'])));
$target = json_encode(array(
'type' => $targettype,
......
......@@ -733,7 +733,7 @@ function conversation(&$a, $items, $mode, $update, $page_mode = 'traditional', $
'like' => '',
'dislike' => '',
'comment' => '',
'conv' => (($preview) ? '' : array('href'=> z_root() . '/display/' . urlencode($item['mid']), 'title'=> t('View in context'))),
'conv' => (($preview) ? '' : array('href'=> z_root() . '/display/' . gen_link_id($item['mid']), 'title'=> t('View in context'))),
'previewing' => $previewing,
'wait' => t('Please wait'),
'thread_level' => 1,
......
......@@ -1018,7 +1018,7 @@ function event_store_item($arr, $event) {
if($wall)
$item_arr['plink'] = z_root() . '/channel/' . $z[0]['channel_address'] . '/?f=&mid=' . urlencode($item_arr['mid']);
else
$item_arr['plink'] = z_root() . '/display/' . urlencode($item_arr['mid']);
$item_arr['plink'] = z_root() . '/display/' . gen_link_id($item_arr['mid']);
$x = q("select * from xchan where xchan_hash = '%s' limit 1",
dbesc($arr['event_xchan'])
......
......@@ -1624,7 +1624,7 @@ logger('revision: ' . $arr['revision']);
if($d2 > $d1)
$arr['item_delayed'] = 1;
$arr['llink'] = z_root() . '/display/' . urlencode($arr['mid']);
$arr['llink'] = z_root() . '/display/' . gen_link_id($arr['mid']);
if(! $arr['plink'])
$arr['plink'] = $arr['llink'];
......@@ -2279,7 +2279,7 @@ function send_status_notifications($post_id,$item) {
if($unfollowed)
return;
$link = z_root() . '/display/' . urlencode($item['mid']);
$link = z_root() . '/display/' . gen_link_id($item['mid']);
$y = q("select id from notify where link = '%s' and uid = %d limit 1",
dbesc($link),
......
......@@ -3124,6 +3124,12 @@ function cleanup_bbcode($body) {
}
function gen_link_id($mid) {
if(strpbrk($mid,':/&?<>"\'') !== false)
return 'b64.' . base64url_encode($mid);
return $mid;
}
// callback for array_walk
function array_trim(&$v,$k) {
......@@ -3132,4 +3138,5 @@ function array_trim(&$v,$k) {
function array_escape_tags(&$v,$k) {
$v = escape_tags($v);
}
\ No newline at end of file
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment