From 72ac5a5437da0a7529387578f060aa817a0a2636 Mon Sep 17 00:00:00 2001 From: Sean Yesmunt Date: Wed, 13 Jan 2021 16:39:46 -0500 Subject: [PATCH] encode share url parts --- ui/component/socialShare/view.jsx | 4 +--- ui/util/url.js | 24 ++++++++++++++---------- 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/ui/component/socialShare/view.jsx b/ui/component/socialShare/view.jsx index a9ac32807..d09fae566 100644 --- a/ui/component/socialShare/view.jsx +++ b/ui/component/socialShare/view.jsx @@ -49,9 +49,7 @@ function SocialShare(props: Props) { const encodedLbryURL: string = generateEncodedLbryURL(SHARE_DOMAIN, lbryWebUrl, includeStartTime, startTimeSeconds); const shareUrl: string = generateShareUrl( SHARE_DOMAIN, - lbryWebUrl, - canonicalUrl, - permanentUrl, + lbryUrl, referralCode, rewardsApproved, includeStartTime, diff --git a/ui/util/url.js b/ui/util/url.js index 854003752..721133b04 100644 --- a/ui/util/url.js +++ b/ui/util/url.js @@ -1,5 +1,6 @@ // Can't use aliases here because we're doing exports/require const PAGES = require('../constants/pages'); +const { parseURI, buildURI } = require('lbry-redux'); exports.formatLbryUrlForWeb = uri => { let newUrl = uri.replace('lbry://', '/').replace(/#/g, ':'); @@ -91,16 +92,7 @@ exports.generateEncodedLbryURL = (domain, lbryWebUrl, includeStartTime, startTim return `${domain}/${encodedPart}`; }; -exports.generateShareUrl = ( - domain, - lbryWebUrl, - canonicalUrl, - permanentUrl, - referralCode, - rewardsApproved, - includeStartTime, - startTime -) => { +exports.generateShareUrl = (domain, lbryUrl, referralCode, rewardsApproved, includeStartTime, startTime) => { let urlParams = new URLSearchParams(); if (referralCode && rewardsApproved) { urlParams.append('r', referralCode); @@ -112,6 +104,18 @@ exports.generateShareUrl = ( const urlParamsString = urlParams.toString(); + const { streamName, streamClaimId, channelName, channelClaimId } = parseURI(lbryUrl); + + let uriParts = { + ...(streamName ? { streamName: encodeURIComponent(streamName) } : {}), + ...(streamClaimId ? { streamClaimId } : {}), + ...(channelName ? { channelName: encodeURIComponent(channelName) } : {}), + ...(channelClaimId ? { channelClaimId } : {}), + }; + + const encodedUrl = buildURI(uriParts, false); + const lbryWebUrl = encodedUrl.replace(/#/g, ':'); + const url = `${domain}/${lbryWebUrl}` + (urlParamsString === '' ? '' : `?${urlParamsString}`); return url; };