Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

protect more markdown usages #22045

Merged
merged 4 commits into from Jan 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 3 additions & 2 deletions go/chat/commands/bot.go
Expand Up @@ -8,6 +8,7 @@ import (

"github.com/keybase/client/go/chat/bots"
"github.com/keybase/client/go/chat/globals"
"github.com/keybase/client/go/chat/utils"
"github.com/keybase/client/go/protocol/chat1"
"github.com/keybase/client/go/protocol/gregor1"
)
Expand Down Expand Up @@ -84,10 +85,10 @@ func (b *Bot) Preview(ctx context.Context, uid gregor1.UID, convID chat1.Convers
var title *string
if cmd.ExtendedDescription.Title != "" {
title = new(string)
*title = cmd.ExtendedDescription.Title
*title = utils.EscapeForDecorate(ctx, cmd.ExtendedDescription.Title)
}
err := b.getChatUI().ChatCommandMarkdown(ctx, convID, &chat1.UICommandMarkdown{
Body: body,
Body: utils.EscapeForDecorate(ctx, body),
Title: title,
})
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion go/chat/flipmanager.go
Expand Up @@ -525,7 +525,7 @@ func (m *FlipManager) addResult(ctx context.Context, status *chat1.UICoinFlipSta
}
items := make([]string, len(hmi.ShuffleItems))
for index, r := range result.Shuffle {
items[index] = hmi.ShuffleItems[r]
items[index] = utils.EscapeForDecorate(ctx, hmi.ShuffleItems[r])
}
var resultInfo chat1.UICoinFlipResult
if hmi.DeckShuffle {
Expand Down
19 changes: 7 additions & 12 deletions go/chat/utils/utils.go
Expand Up @@ -1584,14 +1584,11 @@ func presentAttachmentAssetInfo(ctx context.Context, g *globals.Context, msg cha

func presentPaymentInfo(ctx context.Context, g *globals.Context, msgID chat1.MessageID,
convID chat1.ConversationID, msg chat1.MessageUnboxedValid) []chat1.UIPaymentInfo {

typ, err := msg.MessageBody.MessageType()
if err != nil {
return nil
}

var infos []chat1.UIPaymentInfo

switch typ {
case chat1.MessageType_SENDPAYMENT:
body := msg.MessageBody.Sendpayment()
Expand Down Expand Up @@ -1619,7 +1616,9 @@ func presentPaymentInfo(ctx context.Context, g *globals.Context, msgID chat1.Mes
}
}
}

for index := range infos {
infos[index].Note = EscapeForDecorate(ctx, infos[index].Note)
}
return infos
}

Expand Down Expand Up @@ -1688,6 +1687,8 @@ func PresentDecoratedTextBody(ctx context.Context, g *globals.Context, msg chat1
payments = msgBody.Text().Payments
case chat1.MessageType_FLIP:
body = msgBody.Flip().Text
case chat1.MessageType_REQUESTPAYMENT:
body = msgBody.Requestpayment().Note
default:
return nil
}
Expand Down Expand Up @@ -2465,16 +2466,12 @@ func DecorateWithLinks(ctx context.Context, body string) string {
if shouldSkipLink(bodyMatch) {
continue
}
if !(strings.HasPrefix(bodyMatch, "http://") || strings.HasPrefix(bodyMatch, "https://")) {
url = "http://" + bodyMatch
}
if encoded, err := idna.ToASCII(url); err == nil && encoded != url {
punycode = encoded
}
body, added = DecorateBody(ctx, body, match[lowhit]+offset, match[highhit]-match[lowhit],
chat1.NewUITextDecorationWithLink(chat1.UILinkDecoration{
Display: bodyMatch,
Url: url,
Url: bodyMatch,
Punycode: punycode,
}))
offset += added
Expand All @@ -2488,11 +2485,9 @@ func DecorateWithLinks(ctx context.Context, body string) string {
continue
}
bodyMatch := origBody[match[0]:match[1]]
url := "mailto:" + bodyMatch
body, added = DecorateBody(ctx, body, match[0]+offset, match[1]-match[0],
chat1.NewUITextDecorationWithMailto(chat1.UILinkDecoration{
Display: bodyMatch,
Url: url,
Url: bodyMatch,
}))
offset += added
}
Expand Down
2 changes: 0 additions & 2 deletions go/protocol/chat1/chat_ui.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion go/stellar/loader.go
Expand Up @@ -7,6 +7,7 @@ import (

"golang.org/x/net/context"

"github.com/keybase/client/go/chat/utils"
"github.com/keybase/client/go/libkb"
"github.com/keybase/client/go/protocol/chat1"
"github.com/keybase/client/go/protocol/stellar1"
Expand Down Expand Up @@ -334,7 +335,7 @@ func (p *Loader) uiPaymentInfo(m libkb.MetaContext, summary *stellar1.PaymentLoc
Worth: summary.Worth,
WorthAtSendTime: summary.WorthAtSendTime,
Delta: summary.Delta,
Note: summary.Note,
Note: utils.EscapeForDecorate(m.Ctx(), summary.Note),
IssuerDescription: summary.IssuerDescription,
PaymentID: summary.Id,
SourceAmount: summary.SourceAmountActual,
Expand Down
1 change: 0 additions & 1 deletion protocol/avdl/chat1/chat_ui.avdl
Expand Up @@ -352,7 +352,6 @@ protocol chatUi {
}

record UILinkDecoration {
string display;
string url;
string punycode;
}
Expand Down
4 changes: 0 additions & 4 deletions protocol/json/chat1/chat_ui.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 15 additions & 11 deletions shared/common-adapters/markdown/service-decoration.tsx
Expand Up @@ -166,13 +166,14 @@ const ServiceDecoration = (props: Props) => {
/>
)
} else if (parsed.typ === RPCChatTypes.UITextDecorationTyp.link) {
const link = parsed.link.display
const link = parsed.link.url
const openUrl = link.startsWith('http://') || link.startsWith('https://') ? link : 'http://' + link
return DeeplinksConstants.linkIsKeybaseLink(link) ? (
<KeybaseLink link={link} linkStyle={props.styleOverride.link} wrapStyle={props.styles.wrapStyle} />
) : parsed.link.punycode ? (
<WarningLink
url={parsed.link.url}
display={parsed.link.display}
url={openUrl}
display={parsed.link.url}
punycode={parsed.link.punycode}
linkStyle={props.styleOverride.link}
wrapStyle={props.styles.wrapStyle}
Expand All @@ -182,24 +183,27 @@ const ServiceDecoration = (props: Props) => {
className="hover-underline hover_contained_color_blueDark"
type="BodyPrimaryLink"
style={Styles.collapseStyles([props.styles.wrapStyle, linkStyle, props.styleOverride.link])}
title={parsed.link.display}
onClickURL={parsed.link.url}
onLongPressURL={parsed.link.url}
title={parsed.link.url}
onClickURL={openUrl}
onLongPressURL={openUrl}
>
{parsed.link.display}
{parsed.link.url}
</Text>
)
} else if (parsed.typ === RPCChatTypes.UITextDecorationTyp.mailto) {
const openUrl = parsed.mailto.url.startsWith('mailto:')
? parsed.mailto.url
: 'mailto:' + parsed.mailto.url
return (
<Text
className="hover-underline hover_contained_color_blueDark"
type="BodyPrimaryLink"
style={Styles.collapseStyles([props.styles.wrapStyle, linkStyle, props.styleOverride.mailto])}
title={parsed.mailto.display}
onClickURL={parsed.mailto.url}
onLongPressURL={parsed.mailto.url}
title={parsed.mailto.url}
onClickURL={openUrl}
onLongPressURL={openUrl}
>
{parsed.mailto.display}
{parsed.mailto.url}
</Text>
)
} else if (parsed.typ === RPCChatTypes.UITextDecorationTyp.channelnamemention) {
Expand Down
2 changes: 1 addition & 1 deletion shared/constants/chat2/message.tsx
Expand Up @@ -1027,7 +1027,7 @@ const validUIMessagetoMessage = (
case RPCChatTypes.MessageType.requestpayment:
return makeMessageRequestPayment({
...common,
note: new HiddenString(m.messageBody.requestpayment.note),
note: new HiddenString(m.decoratedTextBody ?? ''),
requestID: m.messageBody.requestpayment.requestID,
requestInfo: uiRequestInfoToChatRequestInfo(m.requestInfo || null),
})
Expand Down
2 changes: 1 addition & 1 deletion shared/constants/types/rpc-chat-gen.tsx

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.